Skip to content

Commit

Permalink
Merge pull request #2 from drewfish/testing
Browse files Browse the repository at this point in the history
converted tests to use mocha & chai
  • Loading branch information
drewfish authored and longlho committed Apr 26, 2020
1 parent 9955aeb commit dcae2f0
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 78 deletions.
1 change: 1 addition & 0 deletions packages/formatjs/packages/intl-messageformat/.gitignore
@@ -1 +1,2 @@
node_modules
coverage
2 changes: 1 addition & 1 deletion packages/formatjs/packages/intl-messageformat/Gruntfile.js
Expand Up @@ -3,7 +3,7 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: ['lib/message.js']
all: ['lib/*.js', 'tests/*.js']
}
});

Expand Down
7 changes: 5 additions & 2 deletions packages/formatjs/packages/intl-messageformat/package.json
Expand Up @@ -29,12 +29,15 @@
"test": "tests"
},
"devDependencies": {
"chai": "~1.8.1",
"grunt": "~0.4.2",
"grunt-cli": "~0.1.11",
"grunt-contrib-jshint": "~0.7.2"
"grunt-contrib-jshint": "~0.7.2",
"istanbul": "~0.1.46",
"mocha": "~1.15.1"
},
"scripts": {
"pretest": "grunt jshint",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "istanbul cover -- _mocha tests/ --reporter spec"
}
}
79 changes: 79 additions & 0 deletions packages/formatjs/packages/intl-messageformat/tests/message.js
@@ -0,0 +1,79 @@
/*jshint node:true */
/*global describe,it */
'use strict';


var expect = require('chai').expect,
MessageFormatter = require('../lib/message.js');


describe('message creation', function () {

it('simple string formatting', function () {
var msg, m;
msg = new MessageFormatter(null, 'My name is ${first} {last}.');
m = msg.format({
first: 'Anthony',
last: 'Pipkin'
});
expect(m).to.equal('My name is Anthony Pipkin.');
});


it ('complex object formatter', function () {
var msg, m;
msg = new MessageFormatter(null, ['Some text before ', {
type: 'plural',
valueName: 'numPeople',
offset: 1,
options: {
one: 'Some message ${ph} with ${#} value',

few: ['Optional prefix text for |few| ', {
type: 'select',
valueName: 'gender',
options: {
male: 'Text for male option with \' single quotes',
female: 'Text for female option with {}',
other: 'Text for default'
}
}, ' optional postfix text'],

other: 'Some messages for the default',

'1': ['Optional prefix text ', {
type: 'select',
valueName: 'gender',
options: {
male: 'Text for male option with \' single quotes',
female: 'Text for female option with {}',
other: 'Text for default'
}
}, ' optional postfix text'],
}
}, ' and text after']);
m = msg.format({
numPeople: 4,
ph: 'whatever',
gender: 'male'
});
expect(m).to.equal("Some text before Optional prefix text for |few| Text for male option with ' single quotes optional postfix text and text after");
});


it('Simple string formatter using a custom formatter for a token', function () {
var msg, m;
msg = new MessageFormatter(null, 'Test formatter d: ${num:d}', {
d: function (locale, val) {
return +val;
}
});
m = msg.format({
num: '010'
});
expect(m).to.equal('Test formatter d: 10');
});

});


75 changes: 0 additions & 75 deletions packages/formatjs/packages/intl-messageformat/tests/test.js

This file was deleted.

0 comments on commit dcae2f0

Please sign in to comment.