How to Load a File for Testing with Jasmine Node?

前端 未结 3 1448
-上瘾入骨i
-上瘾入骨i 2021-02-04 01:02

I have a simple JavaScript file, color.js, and a matching spec file, colorSpec.js.

color.js:

function Color()          


        
3条回答
  •  -上瘾入骨i
    2021-02-04 01:21

    you could load your color.js in the colorSpec.js with a require(). I dont see how jasmine can guess all the dependencies without you telling jasmine what they are exactly in your spec file. Edit : A quick and dirty solution , but maybe there is something builtin Jasmine to do that :

    fs = require('fs')
    myCode = fs.readFileSync('./color.js','utf-8') // depends on the file encoding
    eval(myCode)
    

    then your class should be available with jasmine

    if you call require directly on your file i think you need to create a module and export it

提交回复
热议问题