Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Chai to ignore HTML? #35

Open
zanenkn opened this issue Apr 13, 2019 · 1 comment
Open

How to get Chai to ignore HTML? #35

zanenkn opened this issue Apr 13, 2019 · 1 comment

Comments

@zanenkn
Copy link

zanenkn commented Apr 13, 2019

Problem

Background

Im working on FizzBuzz JS. Specs wouldn't pass because of the inner HTML that Chai is picking up (check out screenshots). Specs pass if I use include instead of eql but I wonder if there's a simple way of "telling" Chai to ignore the HTML tags and still perform the eql.

Spec

 const {FizzBuzz} = require('../spec.helper.js')

describe('Fizz Buzz', () => {
    let fizzBuzz = new FizzBuzz

    it("returns a number if no game rules are met", () => {
        expect(fizzBuzz.check(1)).to.eql(1)
    })

    it("returns Buzz if number is divisible by 5", () => {
        expect(fizzBuzz.check(5)).to.eql("Buzz")
    })

    it ("returns Fizz if number is divisible by 3", () => {
        expect(fizzBuzz.check(3)).to.eql("You entered 3. Fizz!")
    })

    it ("returns FizzBuzz if number is divisible by 15", () => {
        expect(fizzBuzz.check(15)).to.include("FizzBuzz!")
    })
})

Implementation code

function FizzBuzz()  {
    this.check = (number) => {
        if (number % 15 === 0){
            return `You entered ${number}. <br> <h1>FizzBuzz!</h1>`;
        } else if (number % 5 === 0){
            return `You entered ${number}. <br> <h1>Buzz!</h1>`;
        } else if (number % 3 === 0){
            return `You entered ${number}. <br> <h1>FizzBuzz!</h1>`;
        } else {
            return `You entered ${number}.`
        }
    }
}

Screenshots

image

How did you try to solve the problem?

Tried to turn the whole thing into string:

it ("returns Fizz if number is divisible by 3", () => {
        expect(String(fizzBuzz.check(3))).to.eql("You entered 3. Fizz!")
    })

(didn't work)

Read through Chai docs but didn't find anything useful.

@tochman
Copy link
Member

tochman commented Apr 19, 2019

Try using

.to.contain('text')

instead of

.to.eql('text')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants