angular - Jest external library use require('jquery') but return undefined -


hi there,

i using jest-preset-angular angular-cli test angular 4 application uses materialize depends on jquery.

the problem

the problem materialize extends jquery , calls require('jquery') returns undefined when run tests jest.

if (typeof(jquery) === 'undefined') {   var jquery;   // check if require defined function.   if (typeof(require) === 'function') {     jquery = $ = require('jquery');   // else use dollar sign alias.   } else {     jquery = $;   } } 

my actual setup

i mocking jquery this...

import * $ 'jquery/dist/jquery';  object.defineproperty(window, '$', { value: $ }); object.defineproperty(window, 'jquery', { value: $ }); 

and importing materialize after mocking jquery this...

import 'materialize-css/dist/js/materialize'; 

my expectations

as materialize extends jquery , application components using extended methods, needs correctly loaded (including jquery) tests not fails.

any welcome , in advance time!

i feel silly if ever same problem, me updating jest-preset-angular v2.0.5 , jest-junit v2.1.0 solved problem.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -