Get help with testing, discuss unit testing strategies etc.


Post by chauncey-garrett »

What would be the proper/recommended way to add an external library like faker.js to Siesta?

https://github.com/Marak/faker.js

Post by nickolay »

Make it a property of the test class. So you'll need to load the library on the harness page, assign "faker" as a property of the test class (lets say in "initialize" method, don't forget to call SUPER). And then you can do: "t.faker.something()"

Post by chauncey-garrett »

Ok thanks! I thought that'd be what I'd want to do.

Just for clarification though, when you say on the harness page, you do mean index.html (the same place I'd load Siesta's library)?

This is what I've done and faker is available from the test object but it's also in the global scope of the browser window (available as both faker and test.faker, during test execution).

Post by nickolay »

Yes, under harness page I mean "index.html"
This is what I've done and faker is available from the test object but it's also in the global scope of the browser window (available as both faker and test.faker, during test execution).
This means you include it in the preload? Or it is included in your application bundle? If it is loaded only on the harness page, it should be in the global scope of the test page.

Post by chauncey-garrett »

I added faker to the harness page (index.html) and am not using the preload method on the harness. In doing so, it's available in the global scope of the test page.

Post by nickolay »

Shouldn't be like that, then probably faker is loaded by your app somehow (bundled with webpack or something?). In the breakpoint inside the test you can verify it with "window.faker === window.parent.faker" - should be false - different copies of faker.

Post Reply