0
votes

I have setup Jasmine to run my tests in JS. The tests runs and works in Specrunner but I want to use jasmine in my command line to run the tests but I get

1) Account Account balance to be 0
  Message:
    ReferenceError: Account is not defined
  Stack:
    ReferenceError: Account is not defined
        at UserContext.<anonymous> (/Users/student/Projects/week_9/tech_tests/bank_tech_test/spec/AccountSpec.js:4:27)
        at <Jasmine>
        at processImmediate (internal/timers.js:456:21)

1 spec, 1 failure
Finished in 0.01 seconds

I have the class Account in my src and it can pass when running the Specrunner.html. Here is my test:

describe("Account", function(){
    describe("Account balance", function(){
        it("to be 0", function(){
            let account = new Account
            expect(account.balance).toBe(0)
        })
    })
})

Am I missing something from my setup of Jasmine?

EDIT: Added account code and file paths

class Account{
    constructor(){
        this.balance = 0
    }
}

my Account.js file path is src/Account.js. my AccountSpec.js path is spec/AccountSpec.js

1

1 Answers

0
votes

When using jasmine, some modules will be automatically loaded (for example describe, it, expect..).

But in your case, you use Account class. So you need to import it in the test and only then you can use it!

If you are using pure NodeJS, you will need following:

  1. Export your class, add module.exports = { Account: Account } at the end of the file.
  2. Import your class in the test, add const { Account } = require('../src/Account') at the start of file.

Read more about export/import for NodeJS.