field unit test + jest and babel-jest versions upgraded + readme update
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-06-22 15:59:29 +02:00
parent 356c1a7b45
commit 837ec554d3
4 changed files with 7208 additions and 1135 deletions

View File

@ -13,8 +13,15 @@ Required applications.
You will need to install globally the following items.
```
# sudo npm install -g jest gulp-cli
$ sudo npm install -g jest gulp-cli
```
For the usage of jest --watch on macOs.
```
$ brew install watchman
```
* [watchman](https://facebook.github.io/watchman/)
## Linux Only Prerequisites
Your user must be on the docker group to use it so you will need to run this command:

View File

@ -1,6 +1,6 @@
describe('Component vnField', () => {
let $element;
let controller;
let $element;
beforeEach(ngModule('vnCore'));
@ -13,12 +13,84 @@ describe('Component vnField', () => {
$element.remove();
});
// Remove this block
describe('clearDisabled binding', () => {
it(`should enable the show property`, () => {
controller.clearDisabled = true;
describe('field get/set', () => {
it('should do nothing when trying to set the same value again', () => {
controller.field = '';
jest.spyOn(controller, 'validateValue');
expect(controller.clearDisabled).toEqual(true);
controller.field = '';
expect(controller.validateValue).toHaveBeenCalledTimes(0);
expect(controller.classList).not.toContain('not-empty');
});
it('should add the class no empty and then call validateValue()', () => {
controller.field = '';
jest.spyOn(controller, 'validateValue');
controller.field = 'someField';
expect(controller.validateValue).toHaveBeenCalledTimes(1);
expect(controller.classList).toContain('not-empty');
});
});
describe('refreshHint()', () => {
it('should add the class invalid if there is an error in the controller', () => {
controller._error = true;
controller.refreshHint();
expect(controller.classList).toContain('invalid');
});
});
describe('onFocus()', () => {
it('should add the class focus', () => {
controller.onFocus(true);
expect(controller.classList).toContain('focused');
});
it('should not add the class focus', () => {
controller.onFocus(false);
expect(controller.classList).not.toContain('focuses');
});
});
describe('buildInput()', () => {
it('should build an input based on the received type', () => {
controller.buildInput('number');
expect(controller.input.tagName).toEqual('INPUT');
expect(controller.input.type).toEqual('number');
});
});
describe('validateValue()', () => {
it('should do nothing if there is no new error to show', () => {
jest.spyOn(controller, 'refreshHint');
controller.inputError = 'old validation message';
controller.buildInput('number');
controller.input.setCustomValidity('old validation message');
controller.validateValue();
expect(controller.refreshHint).not.toHaveBeenCalled();
expect(controller.inputError).toEqual('old validation message');
});
it('should update the input error and call refreshHint', () => {
jest.spyOn(controller, 'refreshHint');
controller.inputError = 'OLD validation message';
controller.buildInput('number');
controller.input.setCustomValidity('NEW validation message');
controller.validateValue();
expect(controller.refreshHint).toHaveBeenCalled();
expect(controller.inputError).toEqual('NEW validation message');
});
});
});

8246
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
"@babel/preset-env": "^7.7.7",
"@babel/register": "^7.7.7",
"angular-mocks": "^1.7.9",
"babel-jest": "^24.9.0",
"babel-jest": "^26.0.1",
"babel-loader": "^8.0.6",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^2.1.0",
@ -70,7 +70,7 @@
"jasmine": "^3.5.0",
"jasmine-reporters": "^2.3.2",
"jasmine-spec-reporter": "^4.2.1",
"jest": "^24.9.0",
"jest": "^26.0.1",
"jest-junit": "^8.0.0",
"json-loader": "^0.5.7",
"merge-stream": "^1.0.1",