@vitest/expect 4.1.0-beta.6 → 4.1.1
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 +4 -4
- package/dist/index.js +11 -5
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -793,13 +793,13 @@ interface ChaiMockAssertion {
|
|
|
793
793
|
*/
|
|
794
794
|
nthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
|
|
795
795
|
/**
|
|
796
|
-
* Checks that a spy returned
|
|
797
|
-
* Chai-style equivalent of `
|
|
796
|
+
* Checks that a spy returned a specific value at least once.
|
|
797
|
+
* Chai-style equivalent of `toHaveReturnedWith`.
|
|
798
798
|
*
|
|
799
799
|
* @example
|
|
800
|
-
* expect(spy).to.have.returned
|
|
800
|
+
* expect(spy).to.have.returned('value')
|
|
801
801
|
*/
|
|
802
|
-
|
|
802
|
+
returned: <E>(value: E) => void;
|
|
803
803
|
/**
|
|
804
804
|
* Checks that a spy returned a specific value at least once.
|
|
805
805
|
* Chai-style equivalent of `toHaveReturnedWith`.
|
package/dist/index.js
CHANGED
|
@@ -28,17 +28,18 @@ const ChaiStyleAssertions = (chai, utils) => {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
function defMethod(name, delegateTo) {
|
|
31
|
-
utils.
|
|
31
|
+
utils.addMethod(chai.Assertion.prototype, name, function(...args) {
|
|
32
32
|
const jestMethod = chai.Assertion.prototype[delegateTo];
|
|
33
33
|
if (!jestMethod) {
|
|
34
34
|
throw new Error(`Cannot delegate to ${String(delegateTo)}: method not found. Ensure JestChaiExpect plugin is loaded first.`);
|
|
35
35
|
}
|
|
36
36
|
return jestMethod.call(this, ...args);
|
|
37
|
-
}
|
|
37
|
+
});
|
|
38
38
|
}
|
|
39
|
+
// API to (somewhat) mirror sinon-chai
|
|
40
|
+
// https://github.com/chaijs/sinon-chai
|
|
39
41
|
defProperty("called", "toHaveBeenCalled");
|
|
40
42
|
defProperty("calledOnce", "toHaveBeenCalledOnce");
|
|
41
|
-
defProperty("returned", "toHaveReturned");
|
|
42
43
|
defPropertyWithArgs("calledTwice", "toHaveBeenCalledTimes", 2);
|
|
43
44
|
defPropertyWithArgs("calledThrice", "toHaveBeenCalledTimes", 3);
|
|
44
45
|
defMethod("callCount", "toHaveBeenCalledTimes");
|
|
@@ -46,12 +47,15 @@ const ChaiStyleAssertions = (chai, utils) => {
|
|
|
46
47
|
defMethod("calledOnceWith", "toHaveBeenCalledExactlyOnceWith");
|
|
47
48
|
defMethod("lastCalledWith", "toHaveBeenLastCalledWith");
|
|
48
49
|
defMethod("nthCalledWith", "toHaveBeenNthCalledWith");
|
|
50
|
+
defMethod("returned", "toHaveReturned");
|
|
49
51
|
defMethod("returnedWith", "toHaveReturnedWith");
|
|
50
52
|
defMethod("returnedTimes", "toHaveReturnedTimes");
|
|
51
53
|
defMethod("lastReturnedWith", "toHaveLastReturnedWith");
|
|
52
54
|
defMethod("nthReturnedWith", "toHaveNthReturnedWith");
|
|
53
55
|
defMethod("calledBefore", "toHaveBeenCalledBefore");
|
|
54
56
|
defMethod("calledAfter", "toHaveBeenCalledAfter");
|
|
57
|
+
// TODO: implement
|
|
58
|
+
// defMethod('thrown', 'toHaveThrown')
|
|
55
59
|
};
|
|
56
60
|
|
|
57
61
|
const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
|
@@ -1120,9 +1124,11 @@ function recordAsyncExpect(_test, promise, assertion, error, isSoft) {
|
|
|
1120
1124
|
return promise.then(onFulfilled, onRejected);
|
|
1121
1125
|
},
|
|
1122
1126
|
catch(onRejected) {
|
|
1127
|
+
resolved = true;
|
|
1123
1128
|
return promise.catch(onRejected);
|
|
1124
1129
|
},
|
|
1125
1130
|
finally(onFinally) {
|
|
1131
|
+
resolved = true;
|
|
1126
1132
|
return promise.finally(onFinally);
|
|
1127
1133
|
},
|
|
1128
1134
|
[Symbol.toStringTag]: "Promise"
|
|
@@ -1731,7 +1737,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
1731
1737
|
}
|
|
1732
1738
|
throw err;
|
|
1733
1739
|
});
|
|
1734
|
-
return recordAsyncExpect(test, promise, createAssertionMessage(utils, this, !!args.length), error);
|
|
1740
|
+
return recordAsyncExpect(test, promise, createAssertionMessage(utils, this, !!args.length), error, utils.flag(this, "soft"));
|
|
1735
1741
|
};
|
|
1736
1742
|
} });
|
|
1737
1743
|
return proxy;
|
|
@@ -1772,7 +1778,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
1772
1778
|
}
|
|
1773
1779
|
throw err;
|
|
1774
1780
|
});
|
|
1775
|
-
return recordAsyncExpect(test, promise, createAssertionMessage(utils, this, !!args.length), error);
|
|
1781
|
+
return recordAsyncExpect(test, promise, createAssertionMessage(utils, this, !!args.length), error, utils.flag(this, "soft"));
|
|
1776
1782
|
};
|
|
1777
1783
|
} });
|
|
1778
1784
|
return proxy;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/expect",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.1",
|
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"@types/chai": "^5.2.2",
|
|
40
40
|
"chai": "^6.2.2",
|
|
41
41
|
"tinyrainbow": "^3.0.3",
|
|
42
|
-
"@vitest/spy": "4.1.
|
|
43
|
-
"@vitest/utils": "4.1.
|
|
42
|
+
"@vitest/spy": "4.1.1",
|
|
43
|
+
"@vitest/utils": "4.1.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@vitest/runner": "4.1.
|
|
46
|
+
"@vitest/runner": "4.1.1"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "premove dist && rollup -c",
|