Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

Commit 511dddd

Browse files
committed
💚 Add test for percentage difference
1 parent d37c844 commit 511dddd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/image-comparator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class ImageComparator {
6565
const totalPixels = width * height
6666
const percentageDifference = differences / totalPixels
6767
if (this._options.thresholdType === Constants.THRESHOLD_PERCENT) {
68-
threshold = threshold / totalPixels
68+
threshold = percentageDifference
6969
}
7070

7171
// Check if threshold is exceeded

test/index.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Rembrandt', () => {
2626
it('should be fulfilled with passed = true', (done) => {
2727
rembrandt.compare()
2828
.then((result) => {
29-
result.passed.should.be.true
29+
result.passed.should.equal(true)
3030
result.threshold.should.equal(0)
3131
done()
3232
})
@@ -64,8 +64,10 @@ describe('Rembrandt', () => {
6464
it('should be fulfilled with passed = false and thresholds = 3', (done) => {
6565
rembrandt.compare()
6666
.then((result) => {
67-
result.passed.should.be.false
67+
result.passed.should.equal(false)
6868
result.threshold.should.equal(3)
69+
result.differences.should.equal(3)
70+
result.percentageDifference.should.equal(0.75)
6971
done()
7072
})
7173
.catch((e) => done(e))
@@ -86,7 +88,7 @@ describe('Rembrandt', () => {
8688
it('should be fulfilled with `compositionImage`', (done) => {
8789
rembrandt.compare()
8890
.then((result) => {
89-
result.passed.should.be.false
91+
result.passed.should.equal(false)
9092
result.threshold.should.equal(3)
9193
result.should.have.property('compositionImage')
9294

@@ -129,7 +131,7 @@ describe('Rembrandt', () => {
129131
it('should compare against the larger one', (done) => {
130132
rembrandt.compare()
131133
.then((result) => {
132-
result.passed.should.be.false
134+
result.passed.should.equal(false)
133135
result.threshold.should.equal(5)
134136
done()
135137
})

0 commit comments

Comments
 (0)