@vitest/expect 4.0.18 → 4.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +156 -8
- package/dist/index.js +47 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ import { stringify } from '@vitest/utils/display';
|
|
|
9
9
|
import * as chai from 'chai';
|
|
10
10
|
export { chai };
|
|
11
11
|
|
|
12
|
-
declare const MATCHERS_OBJECT: unique symbol;
|
|
13
|
-
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
|
14
|
-
declare const GLOBAL_EXPECT: unique symbol;
|
|
15
|
-
declare const ASYMMETRIC_MATCHERS_OBJECT: unique symbol;
|
|
16
|
-
|
|
17
12
|
interface AsymmetricMatcherInterface {
|
|
18
13
|
asymmetricMatch: (other: unknown, customTesters?: Array<Tester>) => boolean;
|
|
19
14
|
toString: () => string;
|
|
@@ -131,9 +126,18 @@ interface MatcherState {
|
|
|
131
126
|
customTesters: Array<Tester>;
|
|
132
127
|
assertionCalls: number;
|
|
133
128
|
currentTestName?: string;
|
|
129
|
+
/**
|
|
130
|
+
* @deprecated exists only in types
|
|
131
|
+
*/
|
|
134
132
|
dontThrow?: () => void;
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated exists only in types
|
|
135
|
+
*/
|
|
135
136
|
error?: Error;
|
|
136
137
|
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated exists only in types
|
|
140
|
+
*/
|
|
137
141
|
expand?: boolean;
|
|
138
142
|
expectedAssertionsNumber?: number | null;
|
|
139
143
|
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
@@ -141,6 +145,9 @@ interface MatcherState {
|
|
|
141
145
|
isExpectingAssertionsError?: Error | null;
|
|
142
146
|
isNot: boolean;
|
|
143
147
|
promise: string;
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated exists only in types
|
|
150
|
+
*/
|
|
144
151
|
suppressedErrors: Array<Error>;
|
|
145
152
|
testPath?: string;
|
|
146
153
|
utils: ReturnType<typeof getMatcherUtils> & {
|
|
@@ -655,7 +662,7 @@ type VitestAssertion<
|
|
|
655
662
|
> = { [K in keyof A] : A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion);
|
|
656
663
|
type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
|
|
657
664
|
type PromisifyAssertion<T> = Promisify<Assertion<T>>;
|
|
658
|
-
interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, Matchers<T> {
|
|
665
|
+
interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, ChaiMockAssertion, Matchers<T> {
|
|
659
666
|
/**
|
|
660
667
|
* Ensures a value is of a specific type.
|
|
661
668
|
*
|
|
@@ -759,6 +766,140 @@ interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAss
|
|
|
759
766
|
*/
|
|
760
767
|
rejects: PromisifyAssertion<T>;
|
|
761
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* Chai-style assertions for spy/mock testing.
|
|
771
|
+
* These provide sinon-chai compatible assertion names that delegate to Jest-style implementations.
|
|
772
|
+
*/
|
|
773
|
+
interface ChaiMockAssertion {
|
|
774
|
+
/**
|
|
775
|
+
* Checks that a spy was called at least once.
|
|
776
|
+
* Chai-style equivalent of `toHaveBeenCalled`.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* expect(spy).to.have.been.called
|
|
780
|
+
*/
|
|
781
|
+
readonly called: Assertion;
|
|
782
|
+
/**
|
|
783
|
+
* Checks that a spy was called a specific number of times.
|
|
784
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes`.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* expect(spy).to.have.callCount(3)
|
|
788
|
+
*/
|
|
789
|
+
callCount: (count: number) => void;
|
|
790
|
+
/**
|
|
791
|
+
* Checks that a spy was called with specific arguments at least once.
|
|
792
|
+
* Chai-style equivalent of `toHaveBeenCalledWith`.
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* expect(spy).to.have.been.calledWith('arg1', 'arg2')
|
|
796
|
+
*/
|
|
797
|
+
calledWith: <E extends any[]>(...args: E) => void;
|
|
798
|
+
/**
|
|
799
|
+
* Checks that a spy was called exactly once.
|
|
800
|
+
* Chai-style equivalent of `toHaveBeenCalledOnce`.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* expect(spy).to.have.been.calledOnce
|
|
804
|
+
*/
|
|
805
|
+
readonly calledOnce: Assertion;
|
|
806
|
+
/**
|
|
807
|
+
* Checks that a spy was called exactly once with specific arguments.
|
|
808
|
+
* Chai-style equivalent of `toHaveBeenCalledExactlyOnceWith`.
|
|
809
|
+
*
|
|
810
|
+
* @example
|
|
811
|
+
* expect(spy).to.have.been.calledOnceWith('arg1', 'arg2')
|
|
812
|
+
*/
|
|
813
|
+
calledOnceWith: <E extends any[]>(...args: E) => void;
|
|
814
|
+
/**
|
|
815
|
+
* Checks that the last call to a spy was made with specific arguments.
|
|
816
|
+
* Chai-style equivalent of `toHaveBeenLastCalledWith`.
|
|
817
|
+
*
|
|
818
|
+
* @example
|
|
819
|
+
* expect(spy).to.have.been.lastCalledWith('arg1', 'arg2')
|
|
820
|
+
*/
|
|
821
|
+
lastCalledWith: <E extends any[]>(...args: E) => void;
|
|
822
|
+
/**
|
|
823
|
+
* Checks that the nth call to a spy was made with specific arguments.
|
|
824
|
+
* Chai-style equivalent of `toHaveBeenNthCalledWith`.
|
|
825
|
+
*
|
|
826
|
+
* @example
|
|
827
|
+
* expect(spy).to.have.been.nthCalledWith(2, 'arg1', 'arg2')
|
|
828
|
+
*/
|
|
829
|
+
nthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
|
|
830
|
+
/**
|
|
831
|
+
* Checks that a spy returned successfully at least once.
|
|
832
|
+
* Chai-style equivalent of `toHaveReturned`.
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* expect(spy).to.have.returned
|
|
836
|
+
*/
|
|
837
|
+
readonly returned: Assertion;
|
|
838
|
+
/**
|
|
839
|
+
* Checks that a spy returned a specific value at least once.
|
|
840
|
+
* Chai-style equivalent of `toHaveReturnedWith`.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* expect(spy).to.have.returnedWith('value')
|
|
844
|
+
*/
|
|
845
|
+
returnedWith: <E>(value: E) => void;
|
|
846
|
+
/**
|
|
847
|
+
* Checks that a spy returned successfully a specific number of times.
|
|
848
|
+
* Chai-style equivalent of `toHaveReturnedTimes`.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* expect(spy).to.have.returnedTimes(3)
|
|
852
|
+
*/
|
|
853
|
+
returnedTimes: (count: number) => void;
|
|
854
|
+
/**
|
|
855
|
+
* Checks that the last return value of a spy matches the expected value.
|
|
856
|
+
* Chai-style equivalent of `toHaveLastReturnedWith`.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* expect(spy).to.have.lastReturnedWith('value')
|
|
860
|
+
*/
|
|
861
|
+
lastReturnedWith: <E>(value: E) => void;
|
|
862
|
+
/**
|
|
863
|
+
* Checks that the nth return value of a spy matches the expected value.
|
|
864
|
+
* Chai-style equivalent of `toHaveNthReturnedWith`.
|
|
865
|
+
*
|
|
866
|
+
* @example
|
|
867
|
+
* expect(spy).to.have.nthReturnedWith(2, 'value')
|
|
868
|
+
*/
|
|
869
|
+
nthReturnedWith: <E>(n: number, value: E) => void;
|
|
870
|
+
/**
|
|
871
|
+
* Checks that a spy was called before another spy.
|
|
872
|
+
* Chai-style equivalent of `toHaveBeenCalledBefore`.
|
|
873
|
+
*
|
|
874
|
+
* @example
|
|
875
|
+
* expect(spy1).to.have.been.calledBefore(spy2)
|
|
876
|
+
*/
|
|
877
|
+
calledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
878
|
+
/**
|
|
879
|
+
* Checks that a spy was called after another spy.
|
|
880
|
+
* Chai-style equivalent of `toHaveBeenCalledAfter`.
|
|
881
|
+
*
|
|
882
|
+
* @example
|
|
883
|
+
* expect(spy1).to.have.been.calledAfter(spy2)
|
|
884
|
+
*/
|
|
885
|
+
calledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
886
|
+
/**
|
|
887
|
+
* Checks that a spy was called exactly twice.
|
|
888
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes(2)`.
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
891
|
+
* expect(spy).to.have.been.calledTwice
|
|
892
|
+
*/
|
|
893
|
+
readonly calledTwice: Assertion;
|
|
894
|
+
/**
|
|
895
|
+
* Checks that a spy was called exactly three times.
|
|
896
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes(3)`.
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* expect(spy).to.have.been.calledThrice
|
|
900
|
+
*/
|
|
901
|
+
readonly calledThrice: Assertion;
|
|
902
|
+
}
|
|
762
903
|
declare global {
|
|
763
904
|
namespace jest {
|
|
764
905
|
interface Matchers<
|
|
@@ -768,6 +909,13 @@ declare global {
|
|
|
768
909
|
}
|
|
769
910
|
}
|
|
770
911
|
|
|
912
|
+
declare const ChaiStyleAssertions: ChaiPlugin;
|
|
913
|
+
|
|
914
|
+
declare const MATCHERS_OBJECT: unique symbol;
|
|
915
|
+
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
|
916
|
+
declare const GLOBAL_EXPECT: unique symbol;
|
|
917
|
+
declare const ASYMMETRIC_MATCHERS_OBJECT: unique symbol;
|
|
918
|
+
|
|
771
919
|
declare const customMatchers: MatchersObject;
|
|
772
920
|
|
|
773
921
|
declare const JestChaiExpect: ChaiPlugin;
|
|
@@ -802,5 +950,5 @@ declare function isStandardSchema(obj: any): obj is StandardSchemaV1;
|
|
|
802
950
|
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
|
803
951
|
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
|
804
952
|
|
|
805
|
-
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, SchemaMatching, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, customMatchers, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, isStandardSchema, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
|
806
|
-
export type { Assertion, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiPlugin, DeeplyAllowMatchers, ExpectStatic, ExpectationResult, JestAssertion, MatcherHintOptions, MatcherState, Matchers, MatchersObject, PromisifyAssertion, RawMatcherFn, SyncExpectationResult, Tester, TesterContext };
|
|
953
|
+
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, ChaiStyleAssertions, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, SchemaMatching, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, customMatchers, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, isStandardSchema, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
|
954
|
+
export type { Assertion, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiMockAssertion, ChaiPlugin, DeeplyAllowMatchers, ExpectStatic, ExpectationResult, JestAssertion, MatcherHintOptions, MatcherState, Matchers, MatchersObject, PromisifyAssertion, RawMatcherFn, SyncExpectationResult, Tester, TesterContext };
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,52 @@ import { use, util } from 'chai';
|
|
|
8
8
|
import * as chai from 'chai';
|
|
9
9
|
export { chai };
|
|
10
10
|
|
|
11
|
+
const ChaiStyleAssertions = (chai, utils) => {
|
|
12
|
+
function defProperty(name, delegateTo) {
|
|
13
|
+
utils.addProperty(chai.Assertion.prototype, name, function() {
|
|
14
|
+
const jestMethod = chai.Assertion.prototype[delegateTo];
|
|
15
|
+
if (!jestMethod) {
|
|
16
|
+
throw new Error(`Cannot delegate to ${String(delegateTo)}: method not found. Ensure JestChaiExpect plugin is loaded first.`);
|
|
17
|
+
}
|
|
18
|
+
return jestMethod.call(this);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function defPropertyWithArgs(name, delegateTo, ...args) {
|
|
22
|
+
utils.addProperty(chai.Assertion.prototype, name, function() {
|
|
23
|
+
const jestMethod = chai.Assertion.prototype[delegateTo];
|
|
24
|
+
if (!jestMethod) {
|
|
25
|
+
throw new Error(`Cannot delegate to ${String(delegateTo)}: method not found. Ensure JestChaiExpect plugin is loaded first.`);
|
|
26
|
+
}
|
|
27
|
+
return jestMethod.call(this, ...args);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function defMethod(name, delegateTo) {
|
|
31
|
+
utils.addChainableMethod(chai.Assertion.prototype, name, function(...args) {
|
|
32
|
+
const jestMethod = chai.Assertion.prototype[delegateTo];
|
|
33
|
+
if (!jestMethod) {
|
|
34
|
+
throw new Error(`Cannot delegate to ${String(delegateTo)}: method not found. Ensure JestChaiExpect plugin is loaded first.`);
|
|
35
|
+
}
|
|
36
|
+
return jestMethod.call(this, ...args);
|
|
37
|
+
}, () => {});
|
|
38
|
+
}
|
|
39
|
+
defProperty("called", "toHaveBeenCalled");
|
|
40
|
+
defProperty("calledOnce", "toHaveBeenCalledOnce");
|
|
41
|
+
defProperty("returned", "toHaveReturned");
|
|
42
|
+
defPropertyWithArgs("calledTwice", "toHaveBeenCalledTimes", 2);
|
|
43
|
+
defPropertyWithArgs("calledThrice", "toHaveBeenCalledTimes", 3);
|
|
44
|
+
defMethod("callCount", "toHaveBeenCalledTimes");
|
|
45
|
+
defMethod("calledWith", "toHaveBeenCalledWith");
|
|
46
|
+
defMethod("calledOnceWith", "toHaveBeenCalledExactlyOnceWith");
|
|
47
|
+
defMethod("lastCalledWith", "toHaveBeenLastCalledWith");
|
|
48
|
+
defMethod("nthCalledWith", "toHaveBeenNthCalledWith");
|
|
49
|
+
defMethod("returnedWith", "toHaveReturnedWith");
|
|
50
|
+
defMethod("returnedTimes", "toHaveReturnedTimes");
|
|
51
|
+
defMethod("lastReturnedWith", "toHaveLastReturnedWith");
|
|
52
|
+
defMethod("nthReturnedWith", "toHaveNthReturnedWith");
|
|
53
|
+
defMethod("calledBefore", "toHaveBeenCalledBefore");
|
|
54
|
+
defMethod("calledAfter", "toHaveBeenCalledAfter");
|
|
55
|
+
};
|
|
56
|
+
|
|
11
57
|
const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
|
12
58
|
const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
|
13
59
|
const GLOBAL_EXPECT = Symbol.for("expect-global");
|
|
@@ -1872,4 +1918,4 @@ const JestExtend = (chai, utils) => {
|
|
|
1872
1918
|
});
|
|
1873
1919
|
};
|
|
1874
1920
|
|
|
1875
|
-
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, SchemaMatching, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, customMatchers, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, isStandardSchema, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
|
1921
|
+
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, ChaiStyleAssertions, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, SchemaMatching, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, customMatchers, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, isStandardSchema, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/expect",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.1.0-beta.2",
|
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@standard-schema/spec": "^1.
|
|
32
|
+
"@standard-schema/spec": "^1.1.0",
|
|
33
33
|
"@types/chai": "^5.2.2",
|
|
34
|
-
"chai": "^6.2.
|
|
34
|
+
"chai": "^6.2.2",
|
|
35
35
|
"tinyrainbow": "^3.0.3",
|
|
36
|
-
"@vitest/spy": "4.0.
|
|
37
|
-
"@vitest/utils": "4.0.
|
|
36
|
+
"@vitest/spy": "4.1.0-beta.2",
|
|
37
|
+
"@vitest/utils": "4.1.0-beta.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@vitest/runner": "4.0.
|
|
40
|
+
"@vitest/runner": "4.1.0-beta.2"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "premove dist && rollup -c",
|