问题
I'm attempting to set up unit testing in my project, using Jasmine. I am writing my specs in Typescript. My first test is simply checking that a config file returns a value as expected. However, when I import
the config, Jasmine can't find the spec. If I take out the import
and fill in dummy values, everything works fine.
My spec file is:
/// <reference path="../typings/index.d.ts"/>
process.env.ENV = "test";
process.env.TEST_DB_NAME= "test";
import environment = require("../config/config");
describe("Config Tests:", () => {
it("db returns string", () => {
expect(environment.db).toEqual(process.env.TEST_DB_NAME);
});
});
environment.db
should simply return my process.env.TEST_DB_NAME
.
I feel this has to do something with the import
at the beginning making Jasmine not find the describe()
. Anyone know of a way to get Jasmine to work with imports or am I just going about testing this the wrong way?
回答1:
If you call require directly in your file I think you need to create a module and export it. Another way that I have used import successfully has been to create an interface, export it, and then did something like this.
import IUser = UserList.Interfaces.IUser;
You can then use this as the type for a mock object.
来源:https://stackoverflow.com/questions/38269907/jasmine-spec-as-typescript-file