2017-10-24 12 views
0

私は自分のメールチェック機能をユニットテストしています。私は、テスト文字列、記述、期待される結果の辞書を作成して、forループを使ってテストを実行しようとしましたが、うまくいきませんでした。 ここでは、仕様ファイルを1つずつ変更して、どこが間違っているかを確認しています。ジャスミンで辞書の値をテストする

describe("Email", function() { 
    var email; 

    beforeEach(function() { 
    email = undefined; 
    console.log('new test'); 
    }); 

it("should reject undefined", function() { 
    console.log('test 0'); 
    email = undefined; 
    console.log(email); 
    expect(checkEmail(email)).toEqual({'result':false}); 
    }); 

it("should reject numbers", function() { 
    console.log('test 1'); 
    email = 123456; 
    console.log(email); 
    expect(checkEmail(email)).toEqual({'result':false}); 
    }); 
}); 

これは機能します。

describe("Email", function() { 
    var email; 
    **var emails = [undefined, 123456];** 

    beforeEach(function() { 
    email = undefined; 
    console.log('new test'); 
    }); 

it("should reject undefined", function() { 
    console.log('test 1'); 
    **email = emails[0];** 
    console.log(email); 
    expect(checkEmail(email)).toEqual({'result':false}); 
    }); 

it("should reject numbers", function() { 
    console.log('test 2'); 
    **email = emails[1];** 
    console.log(email); 
    expect(checkEmail(email)).toEqual({'result':false}); 
    }); 
}); 

これは機能します。

describe("Email", function() { 
    var email; 
    **var tests = {{'email':undefined}, {'email':123456}};** 

    beforeEach(function() { 
    email = undefined; 
    console.log('new test'); 
    }); 

it("should reject undefined", function() { 
    console.log('test 1'); 
    **email = tests[0].email;** 
    console.log(email); 
    expect(checkEmail(email)).toEqual({'result':false}); 
    }); 

it("should reject numbers", function() { 
    console.log('test 2'); 
    **email = tests[1].email;** 
    console.log(email); 
    expect(checkEmail(email)).toEqual({'result':false}); 
    }); 
}); 

これは機能しません。どうして?

+0

一方で、私は、プログラムのPythonと、このspecファイルを書いています。 – Heuyie

+0

トップコードブロックに 'undefined'という綴りがありません。また、あなたの投稿からうまくいかないことは明らかではありません。 –

+0

@ seth-flowers大胆なスタイルは機能していません。 3番目の例では、私のテスト値は辞書に入っています。そして、突然、私はもうこの試験を行うことができません。 – Heuyie

答えて

0

"辞書"を間違って定義しています。

変更は、この次のいずれかに

var tests = {{'email':undefined}, {'email':123456}} 

var tests = [{'email':undefined}, {'email':123456}]; 
var tests = {0: {'email':undefined}, 1: {'email':123456}}; 
+0

あなたは正しいです!ありがとう! – Heuyie

関連する問題