Skip to content

Commit

Permalink
test: update define expression (#7517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed May 10, 2022
1 parent ba6cae9 commit 86b29e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion playground/define/__tests__/define.spec.ts
@@ -1,7 +1,9 @@
test('string', async () => {
const defines = require('../vite.config.js').define

expect(await page.textContent('.exp')).toBe(String(eval(defines.__EXP__)))
expect(await page.textContent('.exp')).toBe(
String(typeof eval(defines.__EXP__))
)
expect(await page.textContent('.string')).toBe(JSON.parse(defines.__STRING__))
expect(await page.textContent('.number')).toBe(String(defines.__NUMBER__))
expect(await page.textContent('.boolean')).toBe(String(defines.__BOOLEAN__))
Expand Down
2 changes: 1 addition & 1 deletion playground/define/index.html
Expand Up @@ -18,7 +18,7 @@ <h1>Define</h1>

<script type="module">
const __VAR_NAME__ = true // ensure define doesn't replace var name
text('.exp', __EXP__)
text('.exp', typeof __EXP__) // typeof __EXP__ would be `boolean` instead of `string`
text('.string', __STRING__)
text('.number', __NUMBER__)
text('.boolean', __BOOLEAN__)
Expand Down
2 changes: 1 addition & 1 deletion playground/define/vite.config.js
@@ -1,6 +1,6 @@
module.exports = {
define: {
__EXP__: '1 + 1',
__EXP__: 'false',
__STRING__: '"hello"',
__NUMBER__: 123,
__BOOLEAN__: true,
Expand Down

0 comments on commit 86b29e7

Please sign in to comment.