I am currently trying to implement unit testing using Jasmine and CucumberJS in my Angular v9 application. I have followed the tutorial provided by cucumber.io to set up cucumber as the default runner. However, I am facing difficulties in using Jasmine methods. While I have been able to use the expect method, I'm unable to access other functionalities from the Jasmine library such as spyOn
and createSpyObj
. Whenever I try to execute a line of code like:
expect(this.actualAnswer).toBe(expectedAnswer);
, an error is thrown stating TypeError: Cannot read property 'toBe' of undefined at World.<anonymous>
Below is the current state of my project. Any assistance would be greatly appreciated.
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
});
package.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"
}
}