-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb16abd4.61235794.js
1 lines (1 loc) · 7.32 KB
/
db16abd4.61235794.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{158:function(e,t,a){"use strict";a.r(t),a.d(t,"frontMatter",(function(){return o})),a.d(t,"metadata",(function(){return i})),a.d(t,"rightToc",(function(){return s})),a.d(t,"default",(function(){return b}));var r=a(2),n=a(9),c=(a(0),a(163)),o={id:"test-examples",title:"Test Examples",sidebar_label:"Test Examples"},i={id:"test-examples",title:"Test Examples",description:"When writing a tutorial you'll find you need to write tests for a wide variety of scenarios. This section aims to provide examples and inspiration.",source:"@site/docs/test-examples.md",permalink:"/docs/test-examples",editUrl:"https://github.com/coderoad/coderoad-vscode/edit/master/docs/docs/test-examples.md",sidebar_label:"Test Examples",sidebar:"someSidebar",previous:{title:"Initial Commit",permalink:"/docs/init-commit"},next:{title:"Editing a Tutorial",permalink:"/docs/edit-tutorial"}},s=[{value:"Equality",id:"equality",children:[]},{value:"Spy/Listener",id:"spylistener",children:[]},{value:"Dependency Installed",id:"dependency-installed",children:[]},{value:"API Test",id:"api-test",children:[]},{value:"File Creation",id:"file-creation",children:[]},{value:"Regex Code",id:"regex-code",children:[]},{value:"React",id:"react",children:[]},{value:"Testing a Test \ud83e\udd2f",id:"testing-a-test-\ud83e\udd2f",children:[]}],d={rightToc:s};function b(e){var t=e.components,a=Object(n.a)(e,["components"]);return Object(c.b)("wrapper",Object(r.a)({},d,a,{components:t,mdxType:"MDXLayout"}),Object(c.b)("p",null,"When writing a tutorial you'll find you need to write tests for a wide variety of scenarios. This section aims to provide examples and inspiration."),Object(c.b)("p",null,"Integration tests are usable, but slower. Unit tests are fastest whenever possible."),Object(c.b)("p",null,"That said, anything can be tested. I\u2019ll include some examples below of tests I\u2019ve made for inspiration."),Object(c.b)("h3",{id:"equality"},"Equality"),Object(c.b)("p",null,"Testing equality\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-tutorial-js-bug-hunter/commit/75b32ebee89853deb3b4dad6aa8654f89bc72cff"}),"https://github.com/ShMcK/coderoad-tutorial-js-bug-hunter/commit/75b32ebee89853deb3b4dad6aa8654f89bc72cff")),Object(c.b)("h3",{id:"spylistener"},"Spy/Listener"),Object(c.b)("p",null,"Code that listens for something to have been called. Use a spy.\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-fcc-basic-node-and-express/commit/ec62e7b2cd65173a503dc2bd6be71c46f66f7c25"}),"1.2 console log \xb7 ShMcK/coderoad-fcc-basic-node-and-express@ec62e7b \xb7 GitHub")),Object(c.b)("h3",{id:"dependency-installed"},"Dependency Installed"),Object(c.b)("p",null,"Watch for a dependency to be installed.\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-fcc-basic-node-and-express/commit/9e28073eb238a5edd41470edc407a4bfe03ebf80"}),"1.1 install express \xb7 ShMcK/coderoad-fcc-basic-node-and-express@9e28073 \xb7 GitHub")),Object(c.b)("h3",{id:"api-test"},"API Test"),Object(c.b)("p",null,"Code that calls an endpoint and validates the return.\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-fcc-basic-node-and-express/commit/b08cb17822544ee957021c03e53eb57170c93231"}),"2.1 get root \xb7 ShMcK/coderoad-fcc-basic-node-and-express@b08cb17 \xb7 GitHub")),Object(c.b)("h3",{id:"file-creation"},"File Creation"),Object(c.b)("p",null,"Check if a file exists.\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-fcc-basic-node-and-express/commit/eaf4220e6343de2c6bb0dda74e7c347f5e45b242"}),"6.1 create .env \xb7 ShMcK/coderoad-fcc-basic-node-and-express@eaf4220 \xb7 GitHub")),Object(c.b)("h3",{id:"regex-code"},"Regex Code"),Object(c.b)("p",null,"Run a regex matcher to find a code match. Code can expect to be formatted from the provided linter rules.\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-fcc-basic-node-and-express/commit/8b416dcc1e262310658083a4d40090846e257dd8"}),"11.2 body parser middleware \xb7 ShMcK/coderoad-fcc-basic-node-and-express@8b416dc \xb7 GitHub")),Object(c.b)("h3",{id:"react"},"React"),Object(c.b)("p",null,"Test shallow renders with @testing-library/react.\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-tutorial-tweeter/commit/1c248ff9846c5a27c12a2cbbb77cab1d66613be4"}),"setup: working message form input \xb7 ShMcK/coderoad-tutorial-tweeter@1c248ff \xb7 GitHub"),"\nYou can also test hooks with @testing-library/react-hooks\nEg. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/coderoad-tutorial-tweeter/commit/71deafa34fb0c271e57fb1749df184c0df3bcd8b"}),"setup: useText hook refactor \xb7 ShMcK/coderoad-tutorial-tweeter@71deafa \xb7 GitHub")),Object(c.b)("h3",{id:"testing-a-test-\ud83e\udd2f"},"Testing a Test \ud83e\udd2f"),Object(c.b)("p",null,"It's even possible to write tests for tests. The trick is to mock the solution, and run the tests. ",Object(c.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/ShMcK/test-a-test"}),"Eg Test a Test")))}b.isMDXComponent=!0},163:function(e,t,a){"use strict";a.d(t,"a",(function(){return l})),a.d(t,"b",(function(){return f}));var r=a(0),n=a.n(r);function c(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function i(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?o(Object(a),!0).forEach((function(t){c(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):o(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function s(e,t){if(null==e)return{};var a,r,n=function(e,t){if(null==e)return{};var a,r,n={},c=Object.keys(e);for(r=0;r<c.length;r++)a=c[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r<c.length;r++)a=c[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var d=n.a.createContext({}),b=function(e){var t=n.a.useContext(d),a=t;return e&&(a="function"==typeof e?e(t):i({},t,{},e)),a},l=function(e){var t=b(e.components);return n.a.createElement(d.Provider,{value:t},e.children)},p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.a.createElement(n.a.Fragment,{},t)}},u=Object(r.forwardRef)((function(e,t){var a=e.components,r=e.mdxType,c=e.originalType,o=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),l=b(a),u=r,f=l["".concat(o,".").concat(u)]||l[u]||p[u]||c;return a?n.a.createElement(f,i({ref:t},d,{components:a})):n.a.createElement(f,i({ref:t},d))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var c=a.length,o=new Array(c);o[0]=u;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i.mdxType="string"==typeof e?e:r,o[1]=i;for(var d=2;d<c;d++)o[d]=a[d];return n.a.createElement.apply(null,o)}return n.a.createElement.apply(null,a)}u.displayName="MDXCreateElement"}}]);