在灰烬应用套件兴农测试灰烬简单验证 [英] Testing Ember Simple Auth in Ember App Kit with sinon

查看:154
本文介绍了在灰烬应用套件兴农测试灰烬简单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的灰烬应用套件应用测试灰烬简单验证时,模拟服务器登录响应。然而,以下code我得到一个不透明的错误'输入意外结束时,点击动作叫上访问功能:

I would like to mock server login responses when testing Ember Simple Auth in my Ember App Kit application. However, with the following code I get an opaque error 'Unexpected end of input' when the click action is called on the visit function :

var App;

module('Acceptances - SignIn', {
  setup: function(){
    App = startApp();
    this.xhr                = sinon.useFakeXMLHttpRequest();
    this.server             = sinon.fakeServer.create();
    this.server.autoRespond = true;
    sinon.spy(Ember.$, 'ajax');


    this.server.respondWith('POST', '/oauth/token', [
      200,
      { 'Content-Type': 'application/json' },
      '{"access_token":"secret token 2!","token_type":"bearer","expires_in":7200}'
    ]);

  },
  teardown: function() {
    Ember.run(App, 'destroy');
  }
});

test('authentication works correctly', function() {   
  visit('/login').fillIn('#identification', "foo@bar.com").fillIn('#password', "password").click('button[type="submit"]').then(function() {
    ok(!exists('a:contains(Login)'), 'Login button is not displayed when authenticated');
  });
});

该#identification和#password口令输入字段存在,并包含它们的场上存在的提交按钮。

The #identification and #password input fields exists, and the submit button exists on the field that contains them.

我,包括我的头兴农和qunit。难道我打电话兴农了错误的方式,或做一些其他的错误吗?

I am including sinon and qunit in my headers. Am I calling sinon the wrong way or making some other mistake?

编辑:分辨率:按还包括兴农,qunit问题就消失了。好像你不能没有包括兴农,qunit与Ember应用套件qunit测试使用兴农。

Resolution: By also including sinon-qunit the problem disappeared. It seems like you can not use sinon with Ember App Kit qunit tests without including sinon-qunit.

编辑2:我开源与测试,嘲笑与兴农这里登录反应的例子:的 https://github.com/digitalplaywright/eak-simple-auth

Edit 2: I open sourced an example with tests that mocks login responses with sinon here: https://github.com/digitalplaywright/eak-simple-auth

推荐答案

我开源与测试,在的 https://github.com/digitalplaywright/eak-simple-auth

这个例子是 - 采用Ember应用套件制作,恩贝尔简单验证和灰烬。

The example is made using Ember App Kit, Ember Simple Auth, and Ember.

这是我如何使用模拟登录的反应中:

This is how I use mock login responses in the:

var App;

module('Acceptances - SignIn', {
  setup: function(){
    App = startApp();
    this.xhr                = sinon.useFakeXMLHttpRequest();
    this.server             = sinon.fakeServer.create();
    this.server.autoRespond = true;
    sinon.spy(Ember.$, 'ajax');


    this.server.respondWith('POST', '/oauth/token', [
      200,
      { 'Content-Type': 'application/json' },
      '{"access_token":"secret token 2!","token_type":"bearer","expires_in":7200}'
    ]);

  },
  teardown: function() {
    Ember.run(App, 'destroy');
  }
});

test('authentication works correctly', function() {
  visit('/').then(function() {
    ok(exists('a:contains(Login)'), 'Login button is displayed when not authenticated');
    ok(!exists('a:contains(Logout)'), 'Logout button is not displayed when not authenticated');
  });

  visit('/login').fillIn('#identification', "foo@bar.com").fillIn('#password', "password").click('button[type="submit"]').then(function() {
    ok(!exists('a:contains(Login)'), 'Login button is not displayed when authenticated');
    ok(exists('a:contains(Logout)'), 'Logout button is displayed when authenticated');
  });
});

这篇关于在灰烬应用套件兴农测试灰烬简单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆