I am trying some simple code - decode logic using the standard browser functionalities atob()
and btoa()
and I am encountering behaviors I can not fully understand.
I have written a very simple test case
it('converts from base64 to ascii', () => {
const stringA = 'I am Enrico in Asci';
const stringB = atob(stringA);
const stringA1 = btoa(stringB);
console.log('My ASCCI to binary and viceversa', stringA1);
expect(stringA1).toBe(stringA);
});
The test case fails. What I see on the console of Chrome is
Expected 'IamEnricoinAscg=' to be 'I am Enrico in Asci'.
Apparently all spaces have gone and end character is wrong. Any help is appreciated.