I'm trying to run this test:
it("should not select anything (emptiness) by default", function() {
// given
//phantomjs.open("google.com"); // just guessing
// when
var text = wordHighlighter.getSelectedText();
// then
expect(text).toEqual(""); // nothing is selected (yet)
});
With commented phantomjs.open("google.com")
the test passes.
The code I'm trying to test is:
var getSelectedText = function () {
var text = "";
if (window.getSelection) { // windows suppose to be open
text = window.getSelection().toString();
}
return text;
};
Seems I have my npm dependecy set up. At least my test is starting by "grunt" command.
My package.json (for example) looks like this:
{
"name": "project-name",
"version": "0.0.1",
"devDependencies": {
"express": "~4.4.3",
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-karma": "~0.9.0",
"karma": "~0.12.28",
"karma-jasmine": "~0.3.2",
"karma-junit-reporter": "^0.2.2",
"karma-phantomjs-launcher": "~0.1.4",
"phantomjs": "~1.9.7-10",
"karma-ng-html2js-preprocessor" : "~0.1"
}
}
(also I have proper Gruntfile.js
and karma.conf.js
)
UPDATE: I end up with an Error (if uncomment phantomjs line):
ReferenceError: Can't find variable: phantomjs
(I'm not sure how I can access phantomjs if it comes from npm-packages I depend on)
If I do with:
var webPage = require('webpage');
var page = webPage.create();
page.open(...
Then:
ReferenceError: Can't find variable: require
I found this as possible solution: but I do use jasmine 2.x
And that suggests me to split my specs.. Still try to figure it out.
Q: How to open the window (make use of phantomjs
) to make the test working with the window
'open/not undefined ?