{ "data": { "question": { "questionId": "2813", "questionFrontendId": "2704", "boundTopicId": null, "title": "To Be Or Not To Be", "titleSlug": "to-be-or-not-to-be", "content": "
Write a function expect
that helps developers test their code. It should take in any value val
and return an object with the following two functions.
toBe(val)
accepts another value and returns true
if the two values ===
each other. If they are not equal, it should throw an error "Not Equal"
.notToBe(val)
accepts another value and returns true
if the two values !==
each other. If they are equal, it should throw an error "Equal"
.\n
Example 1:
\n\n\nInput: func = () => expect(5).toBe(5)\nOutput: {"value": true}\nExplanation: 5 === 5 so this expression returns true.\n\n\n
Example 2:
\n\n\nInput: func = () => expect(5).toBe(null)\nOutput: {"error": "Not Equal"}\nExplanation: 5 !== null so this expression throw the error "Not Equal".\n\n\n
Example 3:
\n\n\nInput: func = () => expect(5).notToBe(null)\nOutput: {"value": true}\nExplanation: 5 !== null so this expression returns true.\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 423, "dislikes": 89, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "() => expect(5).toBe(5)\n() => expect(5).toBe(null)\n() => expect(5).notToBe(null)", "categoryTitle": "JavaScript", "contributors": [], "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} val\n * @return {Object}\n */\nvar expect = function(val) {\n \n};\n\n/**\n * expect(5).toBe(5); // true\n * expect(5).notToBe(5); // throws \"Equal\"\n */", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "type ToBeOrNotToBe = {\n toBe: (val: any) => boolean;\n notToBe: (val: any) => boolean;\n};\n\nfunction expect(val: any): ToBeOrNotToBe {\n\t\n};\n\n/**\n * expect(5).toBe(5); // true\n * expect(5).notToBe(5); // throws \"Equal\"\n */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"72.1K\", \"totalSubmission\": \"117.5K\", \"totalAcceptedRaw\": 72079, \"totalSubmissionRaw\": 117515, \"acRate\": \"61.3%\"}", "hints": [], "solution": { "id": "1962", "canSeeDetail": false, "paidOnly": true, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "() => expect(5).toBe(5)", "metaData": "{\n \"name\": \"expect\",\n \"params\": [\n {\n \"name\": \"func\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"manual\": true,\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ]\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"javascript\": [\"JavaScript\", \"
Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES6 features.
lodash.js library is included by default.
\\r\\n\\r\\nFor Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.
\"], \"typescript\": [\"Typescript\", \"TypeScript 5.1.6, Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES2022 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }