Skip to content

Commit

Permalink
Fixes unit tests following the changes in v4.6.0
Browse files Browse the repository at this point in the history
Removes the warnings displayed during the unit tests.
Rearranges some tests to suppress the (false) error with PhantomJS.

Signed-off-by: Alexandre Bonneau <[email protected]>
  • Loading branch information
AlexandreBonneau committed May 26, 2020
1 parent d0745b5 commit 4942988
Showing 1 changed file with 53 additions and 34 deletions.
87 changes: 53 additions & 34 deletions test/unit/autoNumeric.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ describe('autoNumeric options and `options.*` methods', () => {

it('should correctly update the minimum and maximum range values', () => {
//XXX Note: The user cannot modify the `minimumValue` and `maximumValue` option if the current value is out of range with those updated options. This attempt will throw an error, and the `minimumValue` or `maximumValue` option will be reverted to the previous valid ones.
spyOn(console, 'warn');

// Initialize the range
aNInput = new AutoNumeric(newInput, AutoNumeric.predefinedOptions.French);
Expand Down Expand Up @@ -2255,24 +2256,32 @@ describe('autoNumeric options and `options.*` methods', () => {
const newInput = document.createElement('input');
document.body.appendChild(newInput);

// minimumValue side
// minimumValue side errors
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.zero,
minimumValue: -1,
minimumValue: 1,
maximumValue: 10,
})).not.toThrow();
})).toThrow();

// maximumValue side errors
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.zero,
minimumValue: 0,
minimumValue: -10,
maximumValue: -1,
})).toThrow();

// minimumValue side
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.zero,
minimumValue: -1,
maximumValue: 10,
})).not.toThrow();

expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.zero,
minimumValue: 1,
minimumValue: 0,
maximumValue: 10,
})).toThrow();
})).not.toThrow();

// maximumValue side
expect(() => new AutoNumeric(newInput, {
Expand All @@ -2287,12 +2296,6 @@ describe('autoNumeric options and `options.*` methods', () => {
maximumValue: 0,
})).not.toThrow();

expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.zero,
minimumValue: -10,
maximumValue: -1,
})).toThrow();

// Special case
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.zero,
Expand All @@ -2311,24 +2314,38 @@ describe('autoNumeric options and `options.*` methods', () => {
const newInput = document.createElement('input');
document.body.appendChild(newInput);

// minimumValue side
// minimumValue side errors
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: -1,
minimumValue: -2,
minimumValue: 1,
maximumValue: 10,
})).not.toThrow();
})).toThrow();

expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: -1,
minimumValue: -1,
minimumValue: 1,
maximumValue: 10,
})).toThrow();

// maximumValue side errors
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: '-1',
minimumValue: -10,
maximumValue: -2,
})).toThrow();

// minimumValue side
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: -1,
minimumValue: -2,
maximumValue: 10,
})).not.toThrow();

expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: -1,
minimumValue: 1,
minimumValue: -1,
maximumValue: 10,
})).toThrow();
})).not.toThrow();

// maximumValue side
expect(() => new AutoNumeric(newInput, {
Expand All @@ -2343,12 +2360,6 @@ describe('autoNumeric options and `options.*` methods', () => {
maximumValue: -1,
})).not.toThrow();

expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: '-1',
minimumValue: -10,
maximumValue: -2,
})).toThrow();

// Special case
expect(() => new AutoNumeric(newInput, {
emptyInputBehavior: '-1',
Expand Down Expand Up @@ -2435,6 +2446,7 @@ describe('autoNumeric options and `options.*` methods', () => {
});

it('should display the given string when the rawValue is set to a specific value', () => {
spyOn(console, 'warn');
aNInput = new AutoNumeric(newInput, { valuesToStrings: AutoNumeric.options.valuesToStrings.zeroDash });
aNInput.set(10);
expect(aNInput.getFormatted()).toEqual('10.00');
Expand Down Expand Up @@ -4055,7 +4067,7 @@ describe('Initialization calls', () => {
currencySymbol: AutoNumeric.options.currencySymbol.franc,
currencySymbolPlacement: AutoNumeric.options.currencySymbolPlacement.suffix,
},
]
],
);
expect(anElement2.getFormatted()).toEqual('');
expect(anElement3.getFormatted()).toEqual('');
Expand All @@ -4078,7 +4090,7 @@ describe('Initialization calls', () => {
currencySymbol: AutoNumeric.options.currencySymbol.franc,
currencySymbolPlacement: AutoNumeric.options.currencySymbolPlacement.suffix,
},
]
],
);
expect(anElement2.getFormatted()).toEqual('');
expect(anElement3.getFormatted()).toEqual('');
Expand Down Expand Up @@ -4243,7 +4255,7 @@ describe('Modifying the options after initialization', () => {
},
{
currencySymbol: 'L',
}
},
);
expect(aNInput.getNumericString()).toEqual('12345678.9');
expect(aNInput.getFormatted()).toEqual('12˙345˙678,9L');
Expand Down Expand Up @@ -4710,6 +4722,7 @@ describe('Instantiated autoNumeric functions', () => {
});

it(`should not return a negative value when inputting a positive one and minimumValue is superior to '0' (cf. issue #284)`, () => {
spyOn(console, 'warn');
aNInput = new AutoNumeric(newInput, { minimumValue: '1', maximumValue: '9999', decimalPlaces: 2 }); // Initiate the autoNumeric input

expect(aNInput.getNumericString()).toEqual('');
Expand Down Expand Up @@ -4778,6 +4791,7 @@ describe('Instantiated autoNumeric functions', () => {
});

it('should respect the minimumValue and maximumValue settings', () => {
spyOn(console, 'warn');
aNInput.update({ minimumValue: '999999.99', maximumValue: '1111111111111.11' });
expect(() => aNInput.set(999999.99)).not.toThrow();
expect(() => aNInput.set(1111111111111.11)).not.toThrow();
Expand Down Expand Up @@ -4810,6 +4824,7 @@ describe('Instantiated autoNumeric functions', () => {
});

it('should respect the minimumValue and maximumValue settings when both limits are negative', () => {
spyOn(console, 'warn');
aNInput.update({ minimumValue: '-4400', maximumValue: '-4200' });
expect(() => aNInput.set(-4400)).not.toThrow();
expect(() => aNInput.set(-4200)).not.toThrow();
Expand All @@ -4833,6 +4848,7 @@ describe('Instantiated autoNumeric functions', () => {
});

it('should throw when the minimumValue and maximumValue settings are inverted', () => {
spyOn(console, 'warn');
expect(() => aNInput.update({ minimumValue: '100', maximumValue: '-666' })).toThrow();
});
});
Expand Down Expand Up @@ -5968,7 +5984,7 @@ describe('`global.*` functions', () => {
{
currencySymbol: AutoNumeric.options.currencySymbol.dollar,
digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.apostrophe,
}
},
);
expect(anElement1.getFormatted()).toEqual("1'223'355,66$");
expect(anElement2.getFormatted()).toEqual("1'223'355,66$");
Expand Down Expand Up @@ -6909,7 +6925,7 @@ describe('Static autoNumeric functions', () => {
AutoNumeric.getPredefinedOptions().French,
{ digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator },
{ currencySymbol : AutoNumeric.options.currencySymbol.pound },
{ currencySymbol : AutoNumeric.options.currencySymbol.dollar }
{ currencySymbol : AutoNumeric.options.currencySymbol.dollar },
)).toEqual('241800.02');
});

Expand All @@ -6926,9 +6942,10 @@ describe('Static autoNumeric functions', () => {
{ digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator },
{ currencySymbol : AutoNumeric.options.currencySymbol.pound },
{ currencySymbol : AutoNumeric.options.currencySymbol.dollar },
]
],
)).toEqual('241800.02');

spyOn(console, 'warn');
expect(AutoNumeric.unformat('-24',
[
'integerPos',
Expand All @@ -6938,7 +6955,7 @@ describe('Static autoNumeric functions', () => {
minimumValue : AutoNumeric.options.minimumValue.tenTrillions,
maximumValue : AutoNumeric.options.maximumValue.tenTrillions,
},
]
],
)).toEqual('-24');
});

Expand All @@ -6954,7 +6971,7 @@ describe('Static autoNumeric functions', () => {
{ digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator },
{ currencySymbol : AutoNumeric.options.currencySymbol.pound },
{ currencySymbol : AutoNumeric.options.currencySymbol.dollar },
]
],
)).toEqual('241800.02');
});

Expand Down Expand Up @@ -7265,7 +7282,7 @@ describe('Static autoNumeric functions', () => {
{ digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator },
{ currencySymbol : AutoNumeric.options.currencySymbol.pound },
{ currencySymbol : AutoNumeric.options.currencySymbol.dollar },
]
],
)).toEqual('241800,02$');

expect(AutoNumeric.format(-24,
Expand All @@ -7277,7 +7294,7 @@ describe('Static autoNumeric functions', () => {
minimumValue : AutoNumeric.options.minimumValue.tenTrillions,
maximumValue : AutoNumeric.options.maximumValue.tenTrillions,
},
]
],
)).toEqual('-24');
});

Expand Down Expand Up @@ -7603,6 +7620,7 @@ describe('Static autoNumeric functions', () => {
expect(() => AutoNumeric.validate({ overrideMinMaxLimits: 'ignore' })).not.toThrow();
expect(() => AutoNumeric.validate({ overrideMinMaxLimits: 'invalid' })).not.toThrow();

spyOn(console, 'warn');
expect(() => AutoNumeric.validate({ maximumValue: '42' })).not.toThrow();
expect(() => AutoNumeric.validate({ maximumValue: '42.4' })).not.toThrow();
expect(() => AutoNumeric.validate({ maximumValue: '42.42' })).not.toThrow();
Expand Down Expand Up @@ -8008,6 +8026,7 @@ describe('Static autoNumeric functions', () => {
expect(() => AutoNumeric.validate({ overrideMinMaxLimits: 42 })).toThrow();
expect(() => AutoNumeric.validate({ overrideMinMaxLimits: true })).toThrow();

spyOn(console, 'warn');
expect(() => AutoNumeric.validate({ maximumValue: true })).toThrow();
expect(() => AutoNumeric.validate({ maximumValue: null })).toThrow();
expect(() => AutoNumeric.validate({ maximumValue: 42 })).toThrow();
Expand Down

0 comments on commit 4942988

Please sign in to comment.