mirror of
https://github.com/strapi/strapi.git
synced 2025-06-27 00:41:25 +00:00
Add test for import default
This commit is contained in:
parent
4f3fdafe37
commit
94749e2eb6
@ -7,4 +7,5 @@ module.exports = {
|
||||
...baseConfig,
|
||||
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
|
||||
roots: [__dirname],
|
||||
testMatch: ['<rootDir>/**/*.test.js'],
|
||||
};
|
||||
|
8
packages/core/utils/lib/__tests__/import-default/cjs.js
Normal file
8
packages/core/utils/lib/__tests__/import-default/cjs.js
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
foo: 'bar',
|
||||
cb() {
|
||||
return 42;
|
||||
},
|
||||
};
|
11
packages/core/utils/lib/__tests__/import-default/esm.js
Normal file
11
packages/core/utils/lib/__tests__/import-default/esm.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
__esModule: true,
|
||||
default: {
|
||||
foo: 'bar',
|
||||
cb() {
|
||||
return 42;
|
||||
},
|
||||
},
|
||||
};
|
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const importDefault = require('../../import-default');
|
||||
|
||||
const getPath = (file) => path.resolve(__dirname, file);
|
||||
|
||||
describe('Import Default', () => {
|
||||
test('ESM', () => {
|
||||
const content = importDefault(getPath('./esm'));
|
||||
|
||||
expect(content).toBeDefined();
|
||||
expect(content).toMatchObject(
|
||||
expect.objectContaining({
|
||||
foo: 'bar',
|
||||
cb: expect.any(Function),
|
||||
})
|
||||
);
|
||||
expect(content.cb()).toBe(42);
|
||||
});
|
||||
|
||||
test('CJS', () => {
|
||||
const content = importDefault(getPath('./cjs'));
|
||||
|
||||
expect(content).toBeDefined();
|
||||
expect(content).toMatchObject(
|
||||
expect.objectContaining({
|
||||
foo: 'bar',
|
||||
cb: expect.any(Function),
|
||||
})
|
||||
);
|
||||
expect(content.cb()).toBe(42);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user