Squire.js | friendly dependency injector for testing Require | REST library
kandi X-RAY | Squire.js Summary
kandi X-RAY | Squire.js Summary
Squire.js is a dependency injector for Require.js users to make mocking dependencies easy!.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Squire.js
Squire.js Key Features
Squire.js Examples and Code Snippets
Community Discussions
Trending Discussions on Squire.js
QUESTION
I have some ES5 example project that I would like to convert to ES6:
https://github.com/stefaneidelloth/testDemoES5
https://github.com/stefaneidelloth/testDemoES6
The examples include a class Qux
which inherits from a class Baa
.
When testing Qux
, I would like to mock Baa
.
For ES5 I use Squire.js to mock AMD module dependencies and the unit tests work just fine.
Unfortunately I could not find a testing framework that supports ES6 (="ECMAScript 2015 Language", ES2015) modules directly. We now have 2020 and there are still no unit tests for ES2015? I already spend a lot of time trying to get these tests working ... and I have the impression that my approach is missing something.
Since I could not find direct support for ES6 tests, I try to stick to karma and use webpack to translate the ES6 module code to ES5 AMD modules for testing.
Lets first consider to use karma in combination with requirejs and ES6 code that has been translated to AMD modules.
A. If I try to mock a translated class Baa
(module 'src/baa') with Squire ... that does not work any more. Webpack puts all dependencies in a single file and when using 'src/qux', my injected 'src/baa' is not considered.
ANSWER
Answered 2020-Jan-07 at 08:48I switched from karma to jest and here is a working demo project:
https://github.com/stefaneidelloth/testDemoES6Jest
The workflow is still based on a transpiler (babel) but that happens in the background and does not really influence the development experience.
Example test code that mocks some ES6 module:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Squire.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page