I am currently getting into TDD and I wanted to write a test for a simple 'String.split()'.
The function should return an array of words that are contained in a String.
export function splitSentence(inputSentence) {
const result = inputSentence.split(' ');
return result;
}
I am using mocha
as testing framework and chai
for the assertion.
Here is the test.
describe('String Split', () => {
it('should split a string into an array of words', () => {
const inputString = 'This is some text';
const expectedResult = ['This', 'is', 'some', 'text'];
expect(splitSentence(inputString)).to.equal(expectedResult);
});
});
While testing everything in the browser console it worked fine so I was confident that it would pass the test. However it failed with the following error message.
AssertionError: expected [ 'This', 'is', 'some', 'text' ] to equal [ 'This', 'is', 'some', 'text' ]`
After looking at the error message it seems like they are both equal so I am currently wondering what went wrong here.
Thank your for your help.