Я хочу провести модульное тестирование, используя Жасмин и Огурец JS для моего приложения Angular v9. Следуя учебнику из cucumber.io , я установил огурец в качестве бегуна по умолчанию. Невозможно использовать методы жасмина, хотя. Выяснили, как использовать ожидаемый метод, но нужен доступ к остальной части библиотеки Jasmine, такой как spyOn
и createSpyObj
. Когда я выполняю строку: expect(this.actualAnswer).toBe(expectedAnswer);
выдается ошибка, говорящая TypeError: Cannot read property 'toBe' of undefined at World.<anonymous> (C:\Users\User\cukejas\features\step_definitions\stepdefs.js:24:28)
Вот что у меня так далеко. Может кто-нибудь помочь, пожалуйста?
stepdefs.js
const assert = require('assert');
const { Given, When, Then } = require('cucumber');
const expect = require('C:\\Users\\User\\cukejas\\node_modules\\jasmine\\lib\\jasmine.js');
function isItFriday(today) {
if (today === "Friday") {
return "TGIF";
} else {
return "Nope";
}
}
Given('today is {string}', function (givenDay) {
this.today = givenDay;
});
When('I ask whether it\'s Friday yet', function () {
this.actualAnswer = isItFriday(this.today);
});
Then('I should be told {string}', function (expectedAnswer) {
// assert.equal(this.actualAnswer, expectedAnswer);
//expect(1); --> This line executes without error
expect(this.actualAnswer).toBe(expectedAnswer); // error thrown here
});
пакет. json
{
"name": "cukejas",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "./node_modules/.bin/cucumber-js -p default",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.0.1",
"@angular/common": "~9.0.1",
"@angular/compiler": "~9.0.1",
"@angular/core": "~9.0.1",
"@angular/forms": "~9.0.1",
"@angular/platform-browser": "~9.0.1",
"@angular/platform-browser-dynamic": "~9.0.1",
"@angular/router": "~9.0.1",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.900.2",
"@angular/cli": "~9.0.2",
"@angular/compiler-cli": "~9.0.1",
"@angular/language-service": "~9.0.1",
"@types/cucumber": "^6.0.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"cucumber": "^6.0.5",
"cucumber-pretty": "^6.0.0",
"cucumber-tsflow": "^3.2.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.7.5"
}
}