Skip to content

Commit

Permalink
tests case names
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Mar 1, 2017
1 parent 74b6c12 commit 74aed7a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
13 changes: 6 additions & 7 deletions tests/createFormatMessage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('createFormatMessage', function () {
});


it('returns message directly (ENV:production, values empty)', function () {
it('[production] returns message from id', function () {
const values = rewireEnv();
const state = getState();
const result = createFormatMessage(state)({
Expand All @@ -79,7 +79,7 @@ describe('createFormatMessage', function () {
resetEnv();
});

it('returns defaultMessage directly (ENV:production, values empty)', function () {
it('[production] returns defaultMessage directly when missing id', function () {
const values = rewireEnv();
const state = getState();
const result = createFormatMessage(state)({
Expand All @@ -91,7 +91,7 @@ describe('createFormatMessage', function () {
resetEnv();
});

it('returns id directly (ENV:production, values empty)', function () {
it('[production] returns id directly when missing id and no default message', function () {
const values = rewireEnv();
const state = getState();
const result = createFormatMessage(state)({
Expand All @@ -105,13 +105,16 @@ describe('createFormatMessage', function () {
it('returns id when invariant is disabled with no message/defaultMessage', function () {
const state = getState();
const invariant = stub();

createFormatMessage.__Rewire__('invariant', invariant);

const result = createFormatMessage(state)({
id: 'test-nothing',
});

expect(result).to.equal('test-nothing');
expect(invariant.called).to.be.true;

createFormatMessage.__ResetDependency__('invariant');
});

Expand All @@ -137,23 +140,19 @@ describe('createFormatMessage', function () {
function rewireEnv() {
const values = {
invariant: stub(),
template: stub()
}
createFormatMessage.__Rewire__('ENV', 'production');
createFormatMessage.__Rewire__('invariant', values.invariant);
createFormatMessage.__Rewire__('template', values.template);
return values;
}

function resetEnv() {
createFormatMessage.__ResetDependency__('ENV');
createFormatMessage.__ResetDependency__('invariant');
createFormatMessage.__ResetDependency__('template');
}

function testResult(result, values, str) {
expect(result).to.equal(str);
expect(values.invariant.called).to.be.false;
expect(values.template.called).to.be.false;
}
});
2 changes: 1 addition & 1 deletion tests/intlReducer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('intlReducer', function () {
expect(result).to.deep.eql(expected);
});

it('updates state even if immutable', function () {
it('[immutable] updates state', function () {
const action = {
type: UPDATE_ACTION,
payload: getUpdatePayload()
Expand Down
20 changes: 17 additions & 3 deletions tests/intlSelector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('intlSelector', function () {
expect(result).to.be.empty;
});

it('returns cache when cache intl and reducer intl is the same.', function () {
it('returns cache when cache locale and reducer locale is the same.', function () {
const intlSelector = createIntlSelector();

const round1 = intlSelector(getState());
Expand All @@ -43,15 +43,29 @@ describe('intlSelector', function () {
expect(round2.messages.alternate).to.be.undefined;
});

it('returns empty object when unable to locale intl even when state is immutable', function () {
it('[immutable] calls MessageFormat with proper variables', function () {
defaultIntlSelector.__Rewire__('MessageFormat', mockMessageFormat);

const intlSelector = createIntlSelector();
const state = getState();
const result = intlSelector(fromJS(state));

expect(result.locale).to.equal(state.locale);
expect(result.messages.test).to.be.a.function;
expect(result.messages.test()).to.equal('test-message');

defaultIntlSelector.__ResetDependency__('MessageFormat');
});

it('[immutable] returns empty object when unable to locale intl', function () {
const intlSelector = createIntlSelector();
const result = intlSelector({
intl: fromJS({})
});
expect(result).to.be.empty;
});

it('returns cache when cache intl and reducer intl is the same even when state is immutable.', function () {
it('[immutable] returns cache when cache locale and reducer locale is the same', function () {
const intlSelector = createIntlSelector();

let state1 = getState();
Expand Down

0 comments on commit 74aed7a

Please sign in to comment.