codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 222 forks source link

Dynamic import spy not working #371

Closed amprew closed 5 years ago

amprew commented 5 years ago

Expected Behavior

When I spy upon System.import like:

spyOn(System, 'import').and.returnValue(Promise.resolve('value to be returned'));

and call like this:

System.import('not real route');

I expect to receive:

Promise -> 'value to be returned'

Actual Behavior

when run:

screen shot 2018-11-06 at 10 59 10

Code

    spyOn(System, 'import').and.returnValue(Promise.resolve('value to be returned'));

    console.log(System.import('not real route'));

How Do We Reproduce?

Follow expected behavior.

alexander-akait commented 5 years ago

@MountainDrew System.import deprecated in webpack@4 and will be remove in webpack@5, better avoid using this

amprew commented 5 years ago

@evilebottnawi - good to know, thanks! With the alternative being import (https://whatwg.github.io/loader/#loader-import), would you recommend spyOn(Loader, 'import')?

alexander-akait commented 5 years ago

@MountainDrew what is spyOn?

amprew commented 5 years ago

@evilebottnawi - ah my bad. It's just a method to overwrite the implemented function, effectively stubbing it. It checks a number of things like called with/number of times... I was effectively asking which Prototype it is built off?

amprew commented 5 years ago

Happy to close this issue. I guess it's a no need to fix 👍

alexander-akait commented 5 years ago

@MountainDrew Feel free to feedback

It's just a method to overwrite the implemented function, effectively stubbing it. It checks a number of things like called with/number of times

Depends on what tool you use for testing, it is better to check it in the documentation for testing tool.