Implement solve(serializedFn, expectedMsg?) where serializedFn is the
stringified source of a zero-argument function — and your code must
reconstruct and call it to observe whether it throws.
solve must handle these cases:
| Call | Behaviour |
|---|---|
solve(fn, undefined) | Passes if the function throws anything. |
solve(fn, 'msg') | Passes if the error message contains 'msg'. |
solve(fn, null) | Passes if the function does not throw. |
Return { pass: boolean, message: string }.
// throws anything
solve('function(){throw new Error("boom")}')
// → { pass: true, message: '' }
// throws with specific message
solve('function(){throw new Error("boom")}', 'boom')
// → { pass: true, message: '' }
// message mismatch
solve('function(){throw new Error("boom")}', 'oops')
// → { pass: false, message: "Expected error message to contain 'oops' but got 'boom'" }
// should not throw
solve('function(){return 42}', null)
// → { pass: true, message: '' }Sample tests