Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some tests to translateFile #10

Merged
merged 3 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions test/dolmetscher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,27 @@ describe('Google translate tests', () => {

const res = await google.translateText(' hallo ');
expect(res.toLowerCase()).to.equal("hello");
});

});
});
describe('translateFile', () => {
it('should translate content of file', async () => {
const res = await google.translateFile(`${__dirname}/example.txt`);
expect(res.toLowerCase()).to.equal("hello how are you");
});
it('fails with empty file', async () => {
try {
const res = await google.translateFile(`${__dirname}/empty.txt`);
} catch (err) {
expect(err).to.equal(`translation file error: The input text length must be of type string between ${mymemory.minChars} and ${mymemory.maxChars} characters`);
}
});
it('fails with non existing file', async () => {
try {
const res = await google.translateFile(`${__dirname}/nonExistFile.txt`);
} catch (err) {
expect(err).to.contain(`translation file error:`);
}
});
});
});

Expand Down Expand Up @@ -82,6 +101,25 @@ describe('Mymemory translate tests', () => {
const res = await mymemory.translateText(' welt ');
expect(res.toLowerCase()).to.equal("world");
});

});
describe('translateFile', () => {
it('should translate content of file', async () => {
const res = await mymemory.translateFile(`${__dirname}/example.txt`);
expect(res.toLowerCase()).to.equal("hello, how are you?")
})
it('fails with empty file', async () => {
try {
const res = await mymemory.translateFile(`${__dirname}/empty.txt`);
} catch (err) {
expect(err).to.equal(`translation file error: The input text length must be of type string between ${mymemory.minChars} and ${mymemory.maxChars} characters`)
}
})
it('fails with non existing file', async () => {
try {
const res = await mymemory.translateFile(`${__dirname}/nonExistFile.txt`);
} catch (err) {
expect(err).to.contain(`translation file error:`)
}
})
})
});
Empty file added test/empty.txt
Empty file.
1 change: 1 addition & 0 deletions test/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hallo, wie geht es dir