Skip to content

Commit

Permalink
Fix AMD bindings and fix AMD test.
Browse files Browse the repository at this point in the history
v3.0.0 incorrectly passed the striptags function to `define`,
when it should have passed in a module factory that returns the
striptags function. See #24.
  • Loading branch information
ericnorris committed Feb 5, 2017
1 parent cd53825 commit 517fd77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/striptags.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@

if (typeof define === 'function' && define.amd) {
// AMD
define([], striptags);
define(function module_factory() { return striptags; });
}

else if (typeof module === 'object' && module.exports) {
Expand Down
16 changes: 8 additions & 8 deletions test/striptags-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ describe('striptags', function() {
let src = fs.readFileSync(path);
let script = new vm.Script(src);

it('should define a node module', function() {
it('should define a Node module', function() {
let module = { exports: {} };

script.runInNewContext({module});

assert.notEqual(module.exports, {});
assert.equal(module.exports.toString(), striptags.toString());
});

it('should define an amd module', function() {
let global = {};
let define = function(dependencies, module) {
global.defined = module;
it('should define an AMD module', function() {
let module = null;
let define = function(module_factory) {
module = module_factory();
};

define.amd = true;

script.runInNewContext({global, define});
script.runInNewContext({define});

assert.notEqual(global.defined, null);
assert.equal(module.toString(), striptags.toString());
});

it('should define a browser global', function() {
Expand Down

0 comments on commit 517fd77

Please sign in to comment.