티스토리 뷰
describe("Discover", function() {
let expect = chai.expect;
// 함수가 없는 테스트는 "pending"이라는 표시가 뜨며 실행되지 않습니다.
// 아래 테스트를 작성하고 테스트가 통과하도록 만드십시오.
it("has a prefix of 6011 and a length of 16", function(){
expect(detectNetwork("6011123456789012")).to.equal("Discover");
});
it("has a prefix of 6011 and a length of 19", function(){
expect(detectNetwork("6011123456789012345")).to.equal("Discover");
});
it("has a prefix of 65 and a length of 16", function(){
expect(detectNetwork("6511123456789012")).to.equal("Discover");
});
it("has a prefix of 65 and a length of 19", function(){
expect(detectNetwork("6511123456789012345")).to.equal("Discover");
});
for (let prefix = 644; prefix <= 649; prefix++) {
it(`has a prefix of ${prefix} and a length of 16`, function() {
expect(detectNetwork(`${prefix}1234567890123`)).to.equal("Discover");
});
it(`has a prefix of ${prefix} and a length of 19`, function() {
expect(detectNetwork(`${prefix}1234567890123456`)).to.equal("Discover");
});
}
});
prefix , firstFourDigits , firstThreeDigits를 따로 slice로 잘라 자릿수를 나눴다.
//const detectNetwork = require("./detectNetwork");
let FILL_ME_IN = "Fill this value in";
describe("Diner's Club", function() {
it("has a prefix of 38 and a length of 14", function() {
// throw new Error("Delete me!");
if (detectNetwork("38345678901234") !== "Diner's Club") {
throw new Error("Test failed");
}
});
it("has a prefix of 39 and a length of 14", function() {
if (detectNetwork("39345678901234") !== "Diner's Club") {
throw new Error("Test failed");
}
});
});
describe("American Express", function() {
let assert = function(isTrue) {
if (!isTrue) {
throw new Error("Test failed");
}
};
it("has a prefix of 34 and a length of 15", function() {
assert(detectNetwork("343456789012345") === "American Express");
});
it("has a prefix of 37 and a length of 15", function() {
assert(detectNetwork("373456789012345") === "American Express");
});
});
describe("Visa", function() {
// Chai는 테스트에 필요한 헬퍼 함수들이 담긴 라이브러리
// Chai는 이전에 만들었던 assert 함수와 동일한 기능을 하는 assert 함수를 제공
let assert = chai.assert;
it("has a prefix of 4 and a length of 13", function() {
assert(detectNetwork("4123456789012") === "Visa");
});
it("has a prefix of 4 and a length of 16", function() {
assert(detectNetwork("4123456789012345") === "Visa");
});
it("has a prefix of 4 and a length of 19", function() {
assert(detectNetwork("4123456789012345678") === "Visa");
});
});
describe("MasterCard", function() {
let expect = chai.expect;
it("has a prefix of 51 and a length of 16", function() {
expect(detectNetwork("5112345678901234")).to.equal("MasterCard");
});
it("has a prefix of 52 and a length of 16", function() {
expect(detectNetwork("5212345678901234")).to.equal("MasterCard");
});
it("has a prefix of 53 and a length of 16", function() {
expect(detectNetwork("5312345678901234")).to.equal("MasterCard");
});
it("has a prefix of 54 and a length of 16", function() {
expect(detectNetwork("5412345678901234")).to.equal("MasterCard");
});
it("has a prefix of 55 and a length of 16", function() {
expect(detectNetwork("5512345678901234")).to.equal("MasterCard");
});
/*let should = chai.should();
it("has a prefix of 54 and a length of 16", function() {
should.equal(detectNetwork("5412345678901234").should.equal("Mastercard");
});
it("has a prefix of 55 and a length of 16", function() {
should.equal(detectNetwork("5512345678901234").should.equal("Mastercard");
});*/
});
describe("Discover", function() {
let expect = chai.expect;
it("has a prefix of 6011 and a length of 16", function(){
expect(detectNetwork("6011123456789012")).to.equal("Discover");
});
it("has a prefix of 6011 and a length of 19", function(){
expect(detectNetwork("6011123456789012345")).to.equal("Discover");
});
it("has a prefix of 65 and a length of 16", function(){
expect(detectNetwork("6511123456789012")).to.equal("Discover");
});
it("has a prefix of 65 and a length of 19", function(){
expect(detectNetwork("6511123456789012345")).to.equal("Discover");
});
for (let prefix = 644; prefix <= 649; prefix++) {
it(`has a prefix of ${prefix} and a length of 16`, function() {
expect(detectNetwork(`${prefix}1234567890123`)).to.equal("Discover");
});
it(`has a prefix of ${prefix} and a length of 19`, function() {
expect(detectNetwork(`${prefix}1234567890123456`)).to.equal("Discover");
});
}
});
const detectNetwork = require("./detectNetwork"); 에서 이중으로 호출해서 에러가 떳다.
index.test.js에서 global detectNetwork = require "../detectNetwork.js"로 전역적으로 정의 하고 있다;로
정규식으로 작성 가능
let dinnerRegex = /^3[89]\d{12}$/
8또는 9
let americanRegex = /^3[47]\d{13}$/;
let visaregex = /^4([?:\d{12}|\d{15}|\d{18})$/;
(?: ) : non - capturing 그룹 구분
^4 4로 시작
let masterRegex = /^$[1-5]\d{14}$/;
let discoverRegex = /65|6011|64[4-9]/;
| or은 한개만 쓴다.
'codestates > section4' 카테고리의 다른 글
Performance의 Opportunities 항목 해결방법 (0) | 2023.03.30 |
---|---|
Unit8 - [최적화] Optimization (0) | 2023.03.30 |
Unit7 - [Testing] TDD (0) | 2023.03.29 |
Github GraphQL API로 Live Data 받아오기 (0) | 2023.03.28 |
Unit6 - [API] GraphQL (0) | 2023.03.28 |