using puppeteer to run unit tests of a class definition raise an "class is not defined"
See original GitHub issueHi,
I’m currently working on a library to replace localStorage using a hybrid model of memory storage and IndexedDB (https://github.com/sagrath23/indexedDB). I want to test my specification of IndexedDBStorage, using Jest and Puppeteer (to get a real instance of window.indexedDB), but, when i execute the test suite, i get this error:
Evaluation failed: ReferenceError: IndexedDBStorage_1 is not defined
at <anonymous>:7:45
at step (tslib.js:129:27)
at Object.next (tslib.js:110:57)
at tslib.js:103:75
at new Promise (<anonymous>)
at __awaiter (tslib.js:99:16)
at <anonymous>:2:36
at ExecutionContext.evaluateHandle (node_modules/puppeteer/lib/ExecutionContext.js:66:13)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
and this is the test case definition:
fit("should create empty storage", (async (done) => {
const browser = await puppeteer.launch()
try {
const page = await browser.newPage()
//to pass __awaiter function
await page.addScriptTag({path: "./tslib.js", content: "text/javascript"})
//to pass IndexedDB Class definition
await page.addScriptTag({path: "./bundle.js", content: "text/javascript"})
// tslint:disable-next-line:only-arrow-functions
const store = await page.evaluate(async function() {
const store = new IndexedDBStorage("idbTest")
await store.init()
return store
})
expect(store).toBeDefined()
expect(store.getStorage()).toBeDefined()
await browser.close()
done()
} catch (err) {
await browser.close()
done.fail(err)
}
}))
Enviroment to reproduce
- Puppeteer version: 0.12.0
- Platform / OS version: Windows 10
- node version: 8.9.1
- Jest version. 21.2.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
using puppeteer to run unit tests of a class definition raise ...
Hi, I'm currently working on a library to replace localStorage using a hybrid model of memory storage and IndexedDB ...
Read more >Run jest unit tests in real browser environment with window ...
So i want to run unit tests inside puppeteer page context environment so covered code (and it's dependencies) can access real window object....
Read more >Using with puppeteer
Use jest-puppeteer Preset. Jest Puppeteer provides all required configuration to run your tests using Puppeteer. First, install jest-puppeteer.
Read more >Puppeteer documentation
Puppeteer is a Node library which provides a high-level API to control Chromium or Chrome over the DevTools Protocol. The Puppeteer API is...
Read more >A Guide to Python Unit Testing with unittest and pytest
Learn what software testing is, and how to run Python unit tests with unittest and pytest, two key frameworks for Python unit testing....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
closing this since this is a babel issue with a good suggested workaround.
It says IndexedDBStorage_1 but your code does not have that. Are you using babel? Seems like the first post had a babel mangle issue. In the meantime, this issue might help you, https://github.com/GoogleChrome/puppeteer/issues/1270