Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit 363f268

Browse files
chore(component-parser.spec.js): add test for scopedSelector (#43)
1 parent e776c34 commit 363f268

3 files changed

Lines changed: 50 additions & 5 deletions

File tree

package-lock.json

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@
5858
"pre-commit": "npm run prettier && eslint . --fix && npm run eslint"
5959
}
6060
}
61-
}
61+
}

tests/component-parser.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const { evaluateAbellBlock } = require('../src/compiler.js');
4+
const vm = require('vm');
35

46
const {
57
parseAttributes,
@@ -141,4 +143,42 @@ describe('parseComponent()', () => {
141143
expect(componentTree.styles.length).toBe(0);
142144
expect(componentTree.scripts.length).toBe(1);
143145
});
146+
147+
it('should inject scopedSelector functions', () => {
148+
const abellFile = 'a'; // the filename is used to generate hash while scoping
149+
const abellContent = `
150+
<AbellComponent>
151+
<script>
152+
scopedSelector('yay').innerHTML;
153+
</script>
154+
</AbellComponent>
155+
`;
156+
157+
const componentTree = parseComponent(abellContent, abellFile, {
158+
filename: 'component-parser.spec.js'
159+
});
160+
161+
const mocks = {
162+
document: {
163+
querySelector: (selector) => {
164+
return {
165+
innerHTML: selector
166+
};
167+
},
168+
querySelectorAll: () => []
169+
}
170+
};
171+
172+
const evaluatedValue = evaluateAbellBlock(
173+
componentTree.scripts[0].content,
174+
// eslint-disable-next-line new-cap
175+
new vm.createContext(mocks),
176+
0,
177+
{
178+
filename: 'component-parser.spec.js'
179+
}
180+
);
181+
182+
expect(evaluatedValue).toBe('yay[data-abell-bnJy]');
183+
});
144184
});

0 commit comments

Comments
 (0)