Skip to content

Commit

Permalink
test: add test for fallback: 'error' option
Browse files Browse the repository at this point in the history
  • Loading branch information
polygonplanet committed Jun 8, 2024
1 parent e79dae6 commit 0891915
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,41 @@ describe('encoding', function() {
assert.deepEqual(decoded, '寿司ビール');
});
});

describe('Raise an Error when characters cannot be represented', function() {
it('SJIS', function() {
var fn = function() {
encoding.convert(utf8, {
to: 'sjis',
from: 'utf-8',
fallback: 'error'
});
};
assert.throws(fn, Error, 'Character cannot be represented: [240, 159, 141, 163]');
});

it('EUC-JP', function() {
var fn = function() {
encoding.convert(utf8, {
to: 'euc-jp',
from: 'utf-8',
fallback: 'error'
});
};
assert.throws(fn, Error, 'Character cannot be represented: [240, 159, 141, 163]');
});

it('JIS', function() {
var fn = function() {
encoding.convert(utf8, {
to: 'jis',
from: 'utf-8',
fallback: 'error'
});
};
assert.throws(fn, Error, 'Character cannot be represented: [240, 159, 141, 163]');
});
});
});
});

Expand Down

0 comments on commit 0891915

Please sign in to comment.