-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accomodate React Native and other environments that might have neither btoa nor Buffer.
- Loading branch information
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* global after, before, describe, it */ | ||
|
||
// Only run in Node.js. | ||
if (typeof window === 'undefined') { | ||
describe('React Native-like environment', function () { | ||
let slug | ||
|
||
before(function () { | ||
global.window = {} | ||
delete require.cache[require.resolve('../slug')] | ||
}) | ||
after(function () { | ||
delete global.window | ||
delete require.cache[require.resolve('../slug')] | ||
}) | ||
const assert = require('assert') | ||
|
||
it('should work for window object with no btoa function', function () { | ||
assert.strictEqual(window.btoa, undefined) | ||
slug = require('../slug') | ||
assert.strictEqual(slug('鳄梨'), '6boe5qko') | ||
assert.strictEqual(slug(String.fromCodePoint(56714, 36991)), 'iombvw') | ||
assert.strictEqual(slug(String.fromCodePoint(56714)), 'ia') | ||
assert.strictEqual(slug(String.fromCodePoint(55296)), 'ia') | ||
}) | ||
}) | ||
} |