0

전자 메일 검사 기능을 단위 테스트하고 있습니다. 테스트 문자열, 설명 및 예상 결과의 사전을 작성하고 for 루프를 사용하여 테스트를 시도했지만 작동하지 않았습니다. 이제 스펙 파일을 하나씩 변경하여 어디서 잘못되었는지 봅니다.Jasmine으로 사전에 값을 테스트하십시오.

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

한편, 내가 프로그래밍 파이썬이 사양 파일을 쓰고 있어요. – Heuyie

+0

최상위 코드 블록에'undefined'라는 철자가 틀립니다. 또한, 귀하의 게시물에서 작동하지 않는 것이 명확하지 않습니다. –

+0

@ seth-flowers 굵게 스타일이 작동하지 않습니다. 세 번째 예에서 테스트 값은 사전에 있습니다. 그리고 갑자기이 시험을 더 이상 할 수 없습니다. – Heuyie

답변

0

"사전"을 잘못 정의했습니다.

변경이 다음 중 하나에

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

:

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

맞습니다! 감사! – Heuyie

관련 문제