Unit testing using Jasmine and TypeScript

后端 未结 7 2009
一生所求
一生所求 2021-01-31 01:26

I am trying to get a unit test written in Typescript using Jasmine to compile. With the following in my unit-test file, Resharper prompts me with a link to import types from jas

7条回答
  •  孤街浪徒
    2021-01-31 02:03

    Include this to your jasmine html file,...

    
    

    ...or install the npm jasmine package:

    npm install --save-dev jasmine
    

    when you are using the second way (jasmine as module) you have to import it:

    var jasmine = require('jasmine');
    

    or

    import jasmine from 'jasmine';
    

    then change the other code:

    jasmine.describe("Person FullName", function () {
        var person;
    
        jasmine.beforeEach(function () {
            person = new Person();
            person.setFirstName("Joe");
            person.setLastName("Smith");
        });
    
        jasmine.it("should concatenate first and last names", function () {
            jasmine.expect(person.getFullName()).toBe("Joe, Smith");
        });
    });
    

    Personally i would prefer the first way without using the jasmine npm module. (I didn't test the module yet)

提交回复
热议问题