Skip to content

Commit

Permalink
Merge pull request naver#50 from egjs/module#g48
Browse files Browse the repository at this point in the history
fix(module): Correction on error message handling
  • Loading branch information
박재성[AjaxUI] committed Oct 26, 2015
2 parents dee9582 + b09ac1f commit 9ad127e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
// jscs:disable maximumLineLength
var templateMessage = [
"[egjs] The {{name}} library must be loaded before {{componentName}}.",
"[egjs] For AMD evnronment (like RequireJS), \"{{name}}\" must be declared, which is required by {{componentName}}.",
"[egjs] The {{componentName}} in {{index}} argument is missing.\n\rDownload {{name}} from [{{url}}].",
"[egjs] For AMD environment (like RequireJS), \"{{name}}\" must be declared, which is required by {{componentName}}.",
"[egjs] The {{index}} argument of {{componentName}} is missing.\n\rDownload {{name}} from [{{url}}].",
"[egjs] The {{name}} parameter of {{componentName}} is not valid.\n\rPlease check and try again.",
"[egjs] The {{componentName}} in {{index}} argument is undefined.\n\rPlease check and try again."
"[egjs] The {{index}} argument of {{componentName}} is undefined.\n\rPlease check and try again."
];

// jscs:enable maximumLineLength

var ordinal = [ "1st", "2nd", "3rd"];

function changeOdinal(index) {
return index > 2 ? index + "th" : ordinal[index];
function changeOrdinal(index) {
return index > 2 ? (index + 1) + "th" : ordinal[index];
}

function replaceStr(str, obj) {
Expand Down Expand Up @@ -56,7 +56,7 @@
for (; i < l; i++) {
param = di[i];
messageInfo = {
"index": changeOdinal(i),
"index": changeOrdinal(i),
"name": param,
"componentName": componentName
};
Expand Down Expand Up @@ -153,4 +153,4 @@
fp.apply(global, result[0]);
}
};
})(window);
})(window);
43 changes: 32 additions & 11 deletions test/js/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ QUnit.module( "module", {
}
});

QUnit.test( "A parameter is undefined.", function( assert ) {
QUnit.test( "When a parameter is undefined.", function( assert ) {
//Given
var param = [window.something];
//When
Expand All @@ -14,11 +14,11 @@ QUnit.test( "A parameter is undefined.", function( assert ) {
function() {
throw eg.module("test",param,function($) {});
},
new Error("[egjs] The test in 1st argument is undefined.\n\rPlease check and try again.")
new Error("[egjs] The 1st argument of test is undefined.\n\rPlease check and try again.")
);
});

QUnit.test( "The dependency library did not regist.", function( assert ) {
QUnit.test( "The dependency library was not registered.", function( assert ) {
//Given
var param = ["notRegist"];
//When
Expand All @@ -31,7 +31,7 @@ QUnit.test( "The dependency library did not regist.", function( assert ) {
);
});

QUnit.test( "The dependency library registed but It does not use amd", function( assert ) {
QUnit.test( "The dependency library was registered, but it does not use AMD", function( assert ) {
//Given
var param = ["jQuery"];
//When
Expand All @@ -40,11 +40,11 @@ QUnit.test( "The dependency library registed but It does not use amd", function(
function() {
throw eg.module("notUseAmd",param,function($) {});
},
new Error("[egjs] The notUseAmd in 1st argument is missing.\n\rDownload jQuery from [http://jquery.com/].")
new Error("[egjs] The 1st argument of notUseAmd is missing.\n\rDownload jQuery from [http://jquery.com/].")
);
});

QUnit.test( "The dependency library registed but It did not define in amd.", function( assert ) {
QUnit.test( "The dependency library was registered, but not defined in AMD.", function( assert ) {
//Given
var param = ["jQuery"];
window.require = function(){
Expand All @@ -59,11 +59,11 @@ QUnit.test( "The dependency library registed but It did not define in amd.", fun
function() {
throw eg.module("notRegisteAmd",param,function($) {});
},
new Error("[egjs] For AMD evnronment (like RequireJS), \"jQuery\" must be declared, which is required by notRegisteAmd." )
new Error("[egjs] For AMD environment (like RequireJS), \"jQuery\" must be declared, which is required by notRegisteAmd." )
);
});

QUnit.test( "The dependency library registed and It defined in amd but It did not load.", function( assert ) {
QUnit.test( "The dependency library was registered and defined in AMD, but not loaded.", function( assert ) {
//Given
var param = ["jQuery"];
window.require = function(){
Expand All @@ -85,7 +85,7 @@ QUnit.test( "The dependency library registed and It defined in amd but It did no
);
});

QUnit.test( "All parameters is object.", function( assert ) {
QUnit.test( "All parameters are object.", function( assert ) {
//Given
var param = {};
var param2 = {};
Expand All @@ -97,7 +97,7 @@ QUnit.test( "All parameters is object.", function( assert ) {
});
});

QUnit.test( "A parameter is string and It did not load amd.", function( assert ) {
QUnit.test( "When a parameter is string and not loaded as AMD.", function( assert ) {
//Given
window.jQuery = function(){};
//When
Expand All @@ -107,7 +107,7 @@ QUnit.test( "A parameter is string and It did not load amd.", function( assert )
});
});

QUnit.test( "A parameter is string and It loaded amd.", function( assert ) {
QUnit.test( "When a parameter is string and not loaded as AMD.", function( assert ) {
//Given
var Hammer = {};
window.require = function(){
Expand All @@ -125,3 +125,24 @@ QUnit.test( "A parameter is string and It loaded amd.", function( assert ) {
assert.strictEqual(Hammer, HM);
});
});

QUnit.test( "Check parameters ordinal numbers.", function( assert ) {
//Given
var param = [ 1, 1, 1, 1, 1 ];
//When

[ "1st", "2nd", "3rd", "4th", "5th" ].forEach(function(v,i) {
//Then
assert.throws(
function() {
var arr = param.concat();
arr[i] = window.something;

throw eg.module("test",arr,function($) {});
},
new Error("[egjs] The "+ v +" argument of test is undefined.\n\rPlease check and try again."),
"Ordinal number for "+ i +" is "+ v +"?"
);

});
});

0 comments on commit 9ad127e

Please sign in to comment.