Skip to content

Commit

Permalink
Merge pull request #30 from kasperpedersen/feature/comment-diff
Browse files Browse the repository at this point in the history
feat: Report differences for comments
  • Loading branch information
i-like-robots authored Apr 19, 2021
2 parents bc4043c + e9dd26f commit 7e79c43
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
function thing (ast) {
if (ast.nodeName === '#text') {
return `text "${ast.value}"`
} else if (ast.nodeName === '#comment') {
return `comment "${ast.data}"`
} else if (ast.tagName) {
return `tag <${ast.tagName}>`
} else if (ast.name && ast.value) {
Expand Down
24 changes: 24 additions & 0 deletions tests/spec/chai-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ describe('Chai HTML', () => {
expect(e.message).to.equal('text "Hej world!" was changed to text "Hello world!"')
}
})

it('detects comment changes', () => {
try {
expect('<p>Hello world!</p><!-- Hello -->').html.to.equal('<p>Hello world!</p><!-- Hej -->')
} catch (e) {
expect(e.message).to.equal('comment " Hej " was changed to comment " Hello "')
}
})
})

context('additions', () => {
Expand All @@ -171,6 +179,14 @@ describe('Chai HTML', () => {
expect(e.message).to.equal('text " Hej!" has been added')
}
})

it('detects comment added', () => {
try {
expect('<p>Hello world!</p><!-- Hej! -->').html.to.equal('<p>Hello world!</p>')
} catch (e) {
expect(e.message).to.equal('comment " Hej! " has been added')
}
})
})

context('deletions', () => {
Expand All @@ -197,6 +213,14 @@ describe('Chai HTML', () => {
expect(e.message).to.equal('text " Hej!" has been removed')
}
})

it('detects comment removed', () => {
try {
expect('<p>Hello world!</p>').html.to.equal('<p>Hello world!</p> <!-- Hej! -->')
} catch (e) {
expect(e.message).to.equal('comment " Hej! " has been removed')
}
})
})
})
})

0 comments on commit 7e79c43

Please sign in to comment.