Tag: 茉莉花

在Protractor JS中使用“if语句”时如何解决关于“无效select器”的错误?

我想要使​​用一个不可见的元素作为一个条件,如果它提出了X和否则做Y. 我已经尝试使用这个元素的类作为定位器和他的ng模型和绑定,但他们都没有工作:/ 请您的协助解决这个问题,非常感谢。 这是我有问题的testing用例: describe('LiveSite Portal – Existing client send new message', function() { var msgBox = expect(element(by.css(".final-container")).isPresent()).toBe(true); //var msgBox = element.all(by.css('#main_container > main > div > div > section > div.row.cz-content.inner-content.full-height > div > div.action.ng-scope > footer > form > div.row.form-control.textarea-holder.ng-isolate-scope.ng-hide > textarea')); var EC = protractor.ExpectedConditions; it('LiveSite – Home Page', function() { liveSiteHome(); […]

如何模拟来自http.request(nodejs,jasmine,sinon)的响应

我写了一个小的node模块,使得一个http请求,我有麻烦testing它。 有问题的代码如下所示: module.exports = (function () { var http = require("http"), Promise = require("promise"); var send = function send(requestOptions, requestBody) { return new Promise(function (resolve, reject) { http.request(requestOptions, function (response) { var responseChunks = []; response.on('data', function (chunk) { responseChunks.push(chunk); }); response.on('end', function () { resolve(Buffer.concat(responseChunks)); }); response.on('error', function (e) { reject(e); }); }).end(requestBody); }); […]

如何使用Jasmine和NodeJstestingcallback函数中的逻辑来testingMongoose控制器

在下面的函数中,我使用Mongoose从MongoDB的id中检索一个实体。 var Recipe = require('models/recipe').model; exports.findById = function(req, res) { Recipe.findById(req.params.id, function(err, docs) { if (err) { console.error(err); res.status(500).send(err); } res.json(docs); }); } 我想使用茉莉花来testing,如果我提出了一个错误,当我返回一个500,我想testing如果我把JSON实体上的一切都成功的响应。

如何使EXPECT条件等待承诺解决(代码包装在一个方法中)?

当我尝试在testing体内使用下面的代码片段时,它似乎工作正常,除了这个块之后的代码仍在执行之后,并且testing在最后失败。 var el = element(by.model('name.first')); el.isDisplayed().then(function(condition) { console.log("Is Element Displayed : " + condition); if(!condition) { fail('Test Failed'); } }); 但是,当我把这个代码包装在一个方法(在其他的一些util文件中),如: isMyElementDisplayed: function (element) { var el = element; el.isDisplayed().then(function(condition) { console.log("Is Element Displayed : " + condition); return condition; }); } 然后尝试在我的testing中调用此方法,如: expect(elementActions.isMyElementDisplayed(element(by.model('name.first')))).toBe(true); 它会失败,以下例外。 Expected undefined to be true. 但是我看到消息打印在日志中: Is Element Displayed : […]

量angular器 – 如何在量angular器中设置默认的input语言

我想在我的conf文件中设置一个默认的打字语言。 当我在本地运行我的testing用例时,我无法在运行过程中切换键盘语言,因为它会改variablesangular器的键入语言以及testing失败。 请让我知道,如果你有任何解决scheme,谢谢。

我如何testing我的asynchronous茉莉/ nodejs /诺言代码使用间谍

我有一个名为process-promise的模块(例子被简化了),它有一个单独的function,将一个Promise作为input并对其进行处理 – 它还使用外部模块调用其他function,如下所示: //<process-promise.js> let User = require('user-module'); let processPromise = (promiseObj) => { let user = new User(); promiseObj.then((full_name) => { const [ fname, sname ] = full_name.split(' '); if (fname && sname) { user.setDetails(fname, sname); } else{ console.log('nothing happened'); } }).catch((err) => { console.log(err.message); }); }; module.exports = { processPromise }; 我正在尝试使用Jasmine,Rewire和Jasmine spies按照以下代码对上述函数进行unit […]

非法破坏声明。 的NodeJS

执行下面的代码。 它显示非法break语句错误。 我是新的nodejs请帮我解决这个问题。 代码是: describe('Locating elements using JS', function () { it('Locate H1 tags', function () { browser.get("http://angularjs.org"); element.all(by.js(function () { //This is javascript code which will get h1 elements var elementsArray = new Array(); var anchors = document.querySelectorAll('h3'); for (var i = 0; i < anchors.length; ++i) { if (anchors[i].textContent != '') { elementsArray.push(anchors[i]); […]

如何跨多个testing目录运行茉莉花规格

Jasmine被设置为在一个目录下运行它的规格。 它没有设置从多个spec目录查找和运行testing。 这是我的项目结构: project root: / package.json spec –> jasmine_examples module_a –> spec module_b –> spec module_c –> spec 如果我想从每个模块运行testing,我必须指定每个spec文件。 "spec_files": [ "module_a/spec/spec.js", "module_b/spec/spec.js", "module_c/spec/spec.js" ], 这允许我运行jasmine cli,但它不是可扩展的。 一定会有更好的办法。 我不想手动指定每个包含规范的模块。 我想所有的目录recursionsearch规格。 我只使用JSDom运行这些节点,没有噶或任何无头浏览器。

用jasmine和node.js嘲笑文件系统

我在用茉莉花testing我的文件访问时遇到了麻烦。 我正在写一个简单的监视器,用require('fs').watch注册一个callback函数, require('fs').watch并发出一个包含文件名称的事件,这里没有什么特别的。 但是,当我尝试编写模拟fs模块的testing时,我遇到了一些问题。 这是我的Watcher类(CoffeeScript提前) class Watcher extends EventEmitter constructor: -> @files = [] watch: (filename) -> if !path.existsSync filename throw "File does not exist." @files.push(filename) fs.watchFile filename, (current, previous) -> this.emit('file_changed') 这是我的testing: it 'should check if the file exists', -> spyOn(path, 'existsSync').andReturn(true) watcher.watch 'existing_file.js' expect(path.existsSync).toHaveBeenCalledWith 'existing_file.js' 这个工作正常,通过没有任何问题,但这个完全失败,我不知道我是否正确传递的论据。 it 'should throw an exception if file […]

如何在茉莉花需要的时候把它expression出来?

我试图得到下面的代码,当我发现我已经包含在这个文件的顶部。 你可以在猴子已经加载后如何修补快递对象吗? var express = require('express') Helper = (function() { var HelperObject = function(params) { this.directories = params.directories; }; HelperObject.prototype.addStaticPath = function(app) { for(i = 0; i < this.directories.length; i++) { var static = express.static('/public'); app.use(static); } }; return HelperObject; })();