2025-07-16 22:29:28 +08:00
|
|
|
"use strict";
|
|
|
|
|
2020-09-26 09:05:55 +08:00
|
|
|
module.exports = () => {
|
2024-07-31 04:09:42 +08:00
|
|
|
const warnings = [];
|
2020-09-26 09:05:55 +08:00
|
|
|
let oldWarn;
|
|
|
|
|
2025-07-17 00:13:14 +08:00
|
|
|
beforeEach((done) => {
|
2020-09-26 09:05:55 +08:00
|
|
|
oldWarn = console.warn;
|
2025-07-17 00:13:14 +08:00
|
|
|
console.warn = (m) => warnings.push(m);
|
2020-09-26 09:05:55 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2025-07-17 00:13:14 +08:00
|
|
|
afterEach((done) => {
|
2020-09-26 09:05:55 +08:00
|
|
|
expectWarning();
|
|
|
|
console.warn = oldWarn;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-09-27 17:26:32 +08:00
|
|
|
const expectWarning = (...regexp) => {
|
2025-07-17 00:13:14 +08:00
|
|
|
expect(warnings).toEqual(regexp.map((r) => expect.stringMatching(r)));
|
2020-09-26 09:05:55 +08:00
|
|
|
warnings.length = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
return expectWarning;
|
|
|
|
};
|