Skip to content

Commit 00953c7

Browse files
fix: improve error messages in jasmine
1 parent cd38cad commit 00953c7

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
`ngx-cva-test-suite` provides extensive set of test cases, ensuring your custom controls behave as intended.
1010

11-
It provides various configurations, that allows even with the most non-standard components to be properly tested.
11+
It provides various configurations, that allows even the most non-standard components to be properly tested.
1212

1313
## Installation
1414

libs/ngx-cva-test-suite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Standardise your custom UI form components with ControlValueAccessor Test Suite",
44
"author": "Dmitriy Stepanenko",
55
"license": "MIT",
6-
"version": "1.0.3",
6+
"version": "1.0.4",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/dmitry-stepanenko/ngx-cva-test-suite"

libs/ngx-cva-test-suite/src/lib/ngx-cva-test-suite.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
8080
});
8181

8282
beforeEach(() => {
83-
onChangeSpy = testRunnerResolver.createSpy();
84-
onTouchedSpy = testRunnerResolver.createSpy();
83+
onChangeSpy = testRunnerResolver.createSpy('onChangeSpy');
84+
onTouchedSpy = testRunnerResolver.createSpy('onTouchedSpy');
8585

8686
registerOnChangeSpy = testRunnerResolver.spyOn(componentInstance, 'registerOnChange');
8787
registerOnTouchedSpy = testRunnerResolver.spyOn(componentInstance, 'registerOnTouched');
@@ -96,9 +96,9 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
9696
fixture.detectChanges();
9797
}
9898

99-
function expectComponentValueToBe(expected: any): void {
99+
function expectComponentValueToEqual(expected: any): void {
100100
if (typeof config.getComponentValue === 'function') {
101-
expect(config.getComponentValue(fixture)).toBe(expected);
101+
expect(config.getComponentValue(fixture)).toEqual(expected);
102102
}
103103
}
104104

@@ -121,7 +121,7 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
121121
expect(onChangeSpy).toHaveBeenCalledTimes(0);
122122
expect(onTouchedSpy).toHaveBeenCalledTimes(0);
123123
expect(setDisabledStateSpy).toHaveBeenCalledTimes(0);
124-
expectComponentValueToBe(getValuesFn()[0]);
124+
expectComponentValueToEqual(getValuesFn()[0]);
125125
});
126126

127127
it('value set externally', fakeAsync(() => {
@@ -134,14 +134,14 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
134134
expect(onTouchedSpy).toHaveBeenCalledTimes(0);
135135
componentInstance.writeValue(getValuesFn()[1]);
136136
tick(config.customDelay ?? 100);
137-
expectComponentValueToBe(getValuesFn()[1]);
137+
expectComponentValueToEqual(getValuesFn()[1]);
138138
expect(writeValueSpy).toHaveBeenCalledTimes(2);
139139
testRunnerResolver.expectToHaveBeenNthCalledWith(writeValueSpy, 2, [getValuesFn()[1]]);
140140
expect(onChangeSpy).toHaveBeenCalledTimes(0);
141141
expect(onTouchedSpy).toHaveBeenCalledTimes(0);
142142
componentInstance.writeValue(getValuesFn()[2]);
143143
tick(config.customDelay ?? 100);
144-
expectComponentValueToBe(getValuesFn()[2]);
144+
expectComponentValueToEqual(getValuesFn()[2]);
145145
expect(writeValueSpy).toHaveBeenCalledTimes(3);
146146
testRunnerResolver.expectToHaveBeenNthCalledWith(writeValueSpy, 3, [getValuesFn()[2]]);
147147
expect(onChangeSpy).toHaveBeenCalledTimes(0);
@@ -153,14 +153,14 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
153153
expect(writeValueSpy).toHaveBeenCalledTimes(1);
154154
expect(onChangeSpy).toHaveBeenCalledTimes(0);
155155
expect(onTouchedSpy).toHaveBeenCalledTimes(0);
156-
expectComponentValueToBe(getValuesFn()[0]);
156+
expectComponentValueToEqual(getValuesFn()[0]);
157157
componentInstance.writeValue(null);
158158
tick(config.customDelay ?? 100);
159159
expect(writeValueSpy).toHaveBeenCalledTimes(2);
160160
testRunnerResolver.expectToHaveBeenNthCalledWith(writeValueSpy, 2, [null]);
161161
expect(onChangeSpy).toHaveBeenCalledTimes(0);
162162
expect(onTouchedSpy).toHaveBeenCalledTimes(0);
163-
expectComponentValueToBe(config.resetCustomValue ? config.resetCustomValue.value : null);
163+
expectComponentValueToEqual(config.resetCustomValue ? config.resetCustomValue.value : null);
164164
}));
165165

166166
if (!config.disabledStateNotSupported) {
@@ -170,7 +170,7 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
170170
componentInstance.setDisabledState(true);
171171
tick(config.customDelay ?? 100);
172172
componentInstance.writeValue(getValuesFn()[1]);
173-
expectComponentValueToBe(getValuesFn()[1]);
173+
expectComponentValueToEqual(getValuesFn()[1]);
174174
testRunnerResolver.expectToHaveBeenNthCalledWith(writeValueSpy, 2, [getValuesFn()[1]]);
175175
expect(setDisabledStateSpy).toHaveBeenCalledTimes(1);
176176
expect(onChangeSpy).toHaveBeenCalledTimes(0);
@@ -180,7 +180,7 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
180180
tick(config.customDelay ?? 100);
181181
componentInstance.writeValue(getValuesFn()[2]);
182182
tick(config.customDelay ?? 100);
183-
expectComponentValueToBe(getValuesFn()[2]);
183+
expectComponentValueToEqual(getValuesFn()[2]);
184184
testRunnerResolver.expectToHaveBeenNthCalledWith(writeValueSpy, 3, [getValuesFn()[2]]);
185185
expect(setDisabledStateSpy).toHaveBeenCalledTimes(2);
186186
expect(onChangeSpy).toHaveBeenCalledTimes(0);
@@ -199,7 +199,7 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
199199
expect(onTouchedSpy).toHaveBeenCalledTimes(0);
200200
config.internalValueChangeSetter!(fixture, getValuesFn()[1]);
201201
tick(config.customDelay ?? 100);
202-
expectComponentValueToBe(getValuesFn()[1]);
202+
expectComponentValueToEqual(getValuesFn()[1]);
203203
testRunnerResolver.expectToHaveBeenNthCalledWith(onChangeSpy, 1, [getValuesFn()[1]]);
204204
expect(onTouchedSpy).toHaveBeenCalledTimes(config.supportsOnBlur ? 0 : 1);
205205
}));

libs/ngx-cva-test-suite/src/lib/utils/test-runner-resolver.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ export class TestRunnerResolver {
99
this.testRunnerType = forceType ?? this.getTestRunnerType();
1010
}
1111

12-
createSpy(): CompatibleSpy {
12+
/**
13+
* @param name name of the spy. Will be used only in jasmine
14+
*/
15+
createSpy(name: string): CompatibleSpy {
1316
switch (this.testRunnerType) {
1417
case TestRunnerType.Jasmine:
15-
return jasmine.createSpy();
18+
return jasmine.createSpy(name);
1619

1720
case TestRunnerType.Jest:
1821
return jest.fn();
@@ -44,6 +47,7 @@ export class TestRunnerResolver {
4447
(<any>expect(spyFn)).toHaveBeenNthCalledWith(nthCall, ...params);
4548
} else {
4649
const nthCallArgs = spyFn.calls.argsFor(nthCall - 1);
50+
expect(spyFn).toHaveBeenCalledTimes(nthCall);
4751
expect(nthCallArgs).toEqual(params);
4852
}
4953
}

0 commit comments

Comments
 (0)