{"id":2370,"date":"2023-10-12T09:00:44","date_gmt":"2023-10-12T01:00:44","guid":{"rendered":"https:\/\/white-night.club\/?p=2370"},"modified":"2023-11-09T11:07:50","modified_gmt":"2023-11-09T03:07:50","slug":"ad40","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/12\/ad40\/","title":{"rendered":"2704.\u00a0\u76f8\u7b49\u8fd8\u662f\u4e0d\u76f8\u7b49"},"content":{"rendered":"\n<p>\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u540d\u4e3a\u00a0<code>expect<\/code>\u00a0\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u6d4b\u8bd5\u4ed6\u4eec\u7684\u4ee3\u7801\u3002\u5b83\u5e94\u8be5\u63a5\u53d7\u4efb\u4f55\u503c\u00a0<code>val<\/code>\u00a0\u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570\u7684\u5bf9\u8c61\u3002<\/p>\n\n\n\n<ul>\n<li><code>toBe(val)<\/code>&nbsp;\u63a5\u53d7\u53e6\u4e00\u4e2a\u503c\u5e76\u5728\u4e24\u4e2a\u503c\u76f8\u7b49\uff08&nbsp;<code>===<\/code>&nbsp;\uff09\u65f6\u8fd4\u56de&nbsp;<code>true<\/code>&nbsp;\u3002\u5982\u679c\u5b83\u4eec\u4e0d\u76f8\u7b49\uff0c\u5219\u5e94\u629b\u51fa\u9519\u8bef&nbsp;<code>\"Not Equal\"<\/code>&nbsp;\u3002<\/li>\n\n\n\n<li><code>notToBe(val)<\/code>&nbsp;\u63a5\u53d7\u53e6\u4e00\u4e2a\u503c\u5e76\u5728\u4e24\u4e2a\u503c\u4e0d\u76f8\u7b49\uff08&nbsp;<code>!==<\/code>&nbsp;\uff09\u65f6\u8fd4\u56de&nbsp;<code>true<\/code>&nbsp;\u3002\u5982\u679c\u5b83\u4eec\u76f8\u7b49\uff0c\u5219\u5e94\u629b\u51fa\u9519\u8bef&nbsp;<code>\"Equal\"<\/code>&nbsp;\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>func = () =&gt; expect(5).toBe(5)\n<strong>\u8f93\u51fa\uff1a<\/strong>{\"value\": true}\n<strong>\u89e3\u91ca\uff1a<\/strong>5 === 5 \u56e0\u6b64\u8be5\u8868\u8fbe\u5f0f\u8fd4\u56de true\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>func = () =&gt; expect(5).toBe(null)\n<strong>\u8f93\u51fa\uff1a<\/strong>{\"error\": \"Not Equal\"}\n<strong>\u89e3\u91ca\uff1a<\/strong>5 !== null \u56e0\u6b64\u629b\u51fa\u9519\u8bef \"Not Equal\".\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>func = () =&gt; expect(5).notToBe(null)\n<strong>\u8f93\u51fa\uff1a<\/strong>{\"value\": true}\n<strong>\u89e3\u91ca\uff1a<\/strong>5 !== null \u56e0\u6b64\u8be5\u8868\u8fbe\u5f0f\u8fd4\u56de true.<\/pre>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>JavaScript\u95ed\u5305<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u51fd\u6570\u91cc\u9762\u5957\u51fd\u6570\uff0c\u53c8\u662f\u95ed\u5305\u3002\u8fd9\u91cc\u4e3b\u8981\u8bb0\u5f55\u4e0b\u95ed\u5305\u7684\u5f62\u5f0f\uff0c\u4ee5\u53cathrow Error\u7684\u7528\u6cd5\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cctoBe\u4f1a\u4e0d\u4f1a\u5199\u6210toBe:function(a)\u66f4\u597d\u4e00\u4e9b&#8230;\u867d\u7136\u8fd9\u4e48\u5199\u4e5f\u4e0d\u4f1a\u62a5\u9519\uff0c\u6709\u70b9\u50cfC\u7684\u90a3\u4e00\u5957\u5427\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\r\n * @param {string} val\r\n * @return {Object}\r\n *\/\nvar expect = function(val) {\n    return {\n        toBe(a)\n        {\n            if(val===a)\n                return true\n            else\n                throw Error(\"Not Equal\");\n        },\n        notToBe(b)\n        {\n            if(val!==b)\n                return true\n            else\n                throw Error(\"Equal\");\n        }\n    }\n};\n\/**\n * expect(5).toBe(5); \/\/ true\n * expect(5).notToBe(5); \/\/ throws \"Equal\"\n *\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aJavaScript\u95ed\u5305<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2370"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2370"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2370\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}