Jest Demo
The Jest demo shows how to use Jest for unit testing a yFiles for HTML application.
To run the unit tests:
- Go to the demo's directory
demos-js/testing/jest
. - Run
npm install
. - Run the unit tests with
npm run test
.
yFiles and Jest
While modern JavaScript (or TypeScript) applications usually use JavaScript modules,
Jest's support for native JavaScript modules is still experimental. For this reason,
JavaScript modules code is transpiled. Due to its size, transpiling the yFiles
JavaScript modules library is rather slow. As a workaround, it is possible to map the
JavaScript modules variant of yFiles to its UMD variant, which does not need to be
transpiled. This can be achieved with Jest's
moduleNameMapper
configuration option.
Some parts of yFiles require a complete DOM implementation, which Jest's JSDOM
environment does not provide. To still be able to test code that uses yFiles API that
require a DOM, it is necessary to mock yFiles. See the
tests/ItemFactoryWithMock.test.js
file for details.