Skip to content

Commit cf0e79a

Browse files
committed
extend webpack context mock in tests to have addDependency method
1 parent fe713b7 commit cf0e79a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

__tests__/index.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ describe('js-to-styles-vars-loader', () => {
99
context: path.resolve(),
1010
_module: {
1111
resource: 'fakeResource.scss'
12-
}
12+
},
13+
addDependency () {}
1314
};
1415

1516
it('exports a function', () => {
@@ -83,7 +84,10 @@ describe('js-to-styles-vars-loader', () => {
8384
});
8485

8586
describe('getVarData', () => {
86-
const context = { context: path.resolve()};
87+
const context = {
88+
context: path.resolve(),
89+
addDependency () {}
90+
};
8791

8892
it('gets variable data by modulePath with context', () => {
8993
const varData = operator.getVarData([{path: './mocks/colors.js' }], context);
@@ -99,6 +103,13 @@ describe('js-to-styles-vars-loader', () => {
99103
const varData = operator.getVarData([{ path:'./mocks/corners.js', methodName: 'typeOne'}], context);
100104
expect(varData).toEqual({ tiny: '1%', medium: '3%'});
101105
});
106+
107+
it('call context.addDependecy with modulePath', () => {
108+
spyOn(context, 'addDependency');
109+
const relativePath = './mocks/corners.js';
110+
operator.getVarData([{ path: relativePath, methodName: 'typeOne'}], context);
111+
expect(context.addDependency).toHaveBeenCalledWith(path.resolve(relativePath));
112+
});
102113
});
103114

104115
describe('transformToSassVars', () => {
@@ -117,7 +128,8 @@ describe('js-to-styles-vars-loader', () => {
117128

118129
describe('mergeVarsToContent', () => {
119130
const context = {
120-
context: path.resolve()
131+
context: path.resolve(),
132+
addDependency () {}
121133
};
122134

123135
it('inserts vars to styles content', () => {
@@ -141,7 +153,8 @@ describe('js-to-styles-vars-loader', () => {
141153
it('gets module.resource', () => {
142154
const context = {
143155
_module: {
144-
resource: 'fakeResource'
156+
resource: 'fakeResource',
157+
addDependency () {}
145158
}
146159
};
147160

0 commit comments

Comments
 (0)