feat: mock document.all and test

This commit is contained in:
rnet 2023-12-13 14:47:21 +08:00
parent 6973aa6850
commit eb834cc4a9
3 changed files with 26 additions and 3 deletions

View File

@ -7,8 +7,8 @@
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"test": "jest", "test": "jest ./test/",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand" "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand ./test/"
}, },
"logLevel": "warn", "logLevel": "warn",
"author": "rnet", "author": "rnet",
@ -23,7 +23,7 @@
"request-promise": "^4.2.6", "request-promise": "^4.2.6",
"yargs": "^17.7.2", "yargs": "^17.7.2",
"canvas": "^2.11.2", "canvas": "^2.11.2",
"jsdom": "^22.1.0", "jsdom": "^22.1.0"
}, },
"jest": { "jest": {
"moduleNameMapper": { "moduleNameMapper": {

View File

@ -0,0 +1,23 @@
const getDocumentAll = require('@utils/getDocumentAll').getDocumentAll;
describe('模拟document.all检测', () => {
const da = getDocumentAll({ length: 1 });
console.log(
'运行getDocumentAll({ length: 1 }),返回:', da,
'\n运行getDocumentAll({ length: 1 }) == undefined返回', da == undefined,
'\n运行getDocumentAll({ length: 1 })(),返回:', da(),
'\n运行typeof getDocumentAll({ length: 1 }),返回:', typeof da,
);
test('getDocumentAll({ length: 1 }).length === 1', () => {
expect(da.length).toBe(1);
});
test('getDocumentAll({ length: 1 }) == undefined', () => {
expect(da == undefined).toBe(true);
});
test('typeof getDocumentAll({ length: 1 })', () => {
expect(typeof da).toBe('undefined');
});
test('getDocumentAll({ length: 1 })() === null', () => {
expect(da()).toBe(null);
});
});

BIN
utils/getDocumentAll.node Executable file

Binary file not shown.