Add mock_runtime_test for deno_last_exception.

This commit is contained in:
Ryan Dahl 2018-07-23 14:10:48 -04:00
parent 7baf8a0fd1
commit b87e6d5604
2 changed files with 7 additions and 5 deletions

View file

@ -31,9 +31,8 @@ global.SendSuccess = () => {
}); });
}; };
global.SendByteLength = () => { global.SendWrongByteLength = () => {
deno.recv(msg => { deno.recv(msg => {
assert(msg instanceof ArrayBuffer);
assert(msg.byteLength === 3); assert(msg.byteLength === 3);
}); });
}; };

View file

@ -41,11 +41,14 @@ TEST(MockRuntimeTest, SendSuccess) {
deno_delete(d); deno_delete(d);
} }
TEST(MockRuntimeTest, SendByteLength) { TEST(MockRuntimeTest, SendWrongByteLength) {
Deno* d = deno_new(nullptr, nullptr); Deno* d = deno_new(nullptr, nullptr);
EXPECT_TRUE(deno_execute(d, "a.js", "SendByteLength()")); EXPECT_TRUE(deno_execute(d, "a.js", "SendWrongByteLength()"));
// We pub the wrong sized message, it should throw. // deno_send the wrong sized message, it should throw.
EXPECT_FALSE(deno_send(d, strbuf("abcd"))); EXPECT_FALSE(deno_send(d, strbuf("abcd")));
std::string exception = deno_last_exception(d);
EXPECT_GT(exception.length(), 1);
EXPECT_NE(exception.find("assert"), std::string::npos);
deno_delete(d); deno_delete(d);
} }