DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Popular Topics

article thumbnail
4 Ways To Boost Your Vue.js App With Webpack
If you're looking to give your Vue.js-based web application a little bit of an enhancement, read on to see how Webpack can help with that.
Updated February 10, 2020
by Anthony Gore
· 18,926 Views · 3 Likes
article thumbnail
3 Code Splitting Patterns For Vue.js and Webpack
In this article, a DZone MVB and Vue.js expert shows three methods you can use for architecting an app for code splitting using Vue and Webpack.
Updated February 10, 2020
by Anthony Gore
· 14,035 Views · 3 Likes
article thumbnail
Build A Collapsible Tree Menu With Vue.js Recursive Components
Ever been reading a comment section of a site and wonder how they make that collapsible, indented style view? Read on to find out!
Updated February 10, 2020
by Anthony Gore
· 21,020 Views · 8 Likes
article thumbnail
Managing User Permissions in a Vue.js App
Learn how to restrict user permissions using Vue.js and an open source JavaScript library so users of your can, say, post a comment but not delete a comment.
Updated February 10, 2020
by Anthony Gore
· 29,723 Views · 4 Likes
article thumbnail
Learn Python — Take This 10 Week Transformation Challenge
Use this article as a template to start your journey to becoming a Python master! Start with language basics and move all the way into some basic ML.
Updated February 10, 2020
by Shivashish Thkaur
· 10,845 Views · 15 Likes
article thumbnail
Implementing MUnit And MUnit Matchers With MuleSoft
MUnit is a Mule application testing framework that allows you to build automated tests for your Mule integrations and APIs.
Updated February 10, 2020
by Jitendra Bafna
· 24,036 Views · 4 Likes
article thumbnail
When to ''Unstub'' a Component in a Vue.js Unit Test
To test a component in isolation you can replace it's children components by stubbing them. Vue Test Utils can automatically do this for you with a feature called shallowMount. But what happens if a component is tightly coupled to one of its children? You can still use shallowMount, but you'll then have to selectively "unstub" the tightly coupled child. In this article, I'll show you how to use stubbing to write simpler unit tests. Note: this article was originally posted here on the Vue.js Developers blog on 2019/09/30. Testing in isolation A key idea of unit testing is to test a "unit" of the application in isolation. In component-based frontend apps, we consider the "unit" to be a component. Testing a component in isolation ensures that tests are unaffected by dependencies and other influences of children components. To isolate a component from surrounding components, you can stub it's children components. The diagram below shows how stubbing this way would affect a typical component hierarchy. Stubbing a component usually means replacing it with a simple "stand in" component with no state, logic, and a minimal template. For example, you might replace this: export default { name: "MyComponent", template: "..." props: { ... }, methods: { ... }, computed: { ... } ... }; with this: export default { name: "MyComponentStub" template: "" }; Rather than manually stubbing children components, though, Vue Test Utils offers the shallowMount feature which does it automatically. Coupled components In the real world, components aren't always completely decoupled. Sometimes a component relies on a child component and so the child can't be stubbed without losing some functionality. For example, say we make a button with a cool animation, and we want to reuse it across an app, and so we decide to create a custom component called animated-button. We now have the my-form component that uses this button component. It's been implemented such that my-form is coupled to animated-button, since the latter emits a "click" event that's used to trigger the submit method in the former. MyForm.vue Unit testing my-form Another key idea of unit testing is that we want to test the inputs and outputs of the unit and consider the internals to be a black box. In the my-form component, we should make a unit test where the input is the click of the button, while the output is the Vuex commit. We'll call this test "should commit FORM_SUBMIT when button clicked". We'll create it by first shallow mounting MyForm to isolate it from the influence of any children components as previously prescribed. MyForm.spec.js import { shallowMount } from "@vue/test-utils"; import MyForm from "@/components/MyForm"; describe("MyForm.vue", () => { it("should commit FORM_SUBMIT when button clicked", () => { const wrapper = shallowMount(MyForm); }); }); Next, we'll use the wrapper find API method to find the button component. We pass a CSS selector "animated-button" as the locator strategy. We can then chain the trigger method and pass "click" as the argument. This is how we generate the input of the test. We can then assert that a Vuex commit gets made (probably using a spy, but that's not relevant to this article so I won't detail it). MyForm.spec.js it("should commit FORM_SUBMIT when button clicked", () => { const wrapper = shallowMount(MyForm); wrapper.find("animated-button").trigger("click"); // assert that $store.commit was called }); If we try to run that, we'll get this error from Vue Test Utils: find did not return animated-button, cannot call trigger() on empty Wrapper Is the CSS selector wrong? No, the issue is that we shallow mounted the component, so all the children were stubbed. The auto-stub process changes the name of AnimatedButton to "animated-button-stub" in the template. But changing the selector from "animated-button" to "animated-button-stub" is not a solution. Auto-stubs have no internal logic, so the click event we trigger on it is not being listened to anyway. Selective unstubbing We still want to shallow mount my-form, as we want to ensure it's isolated from the influence of its children. But animated-button is an exception as it's functionality is required for the test. Vue Test Utils allows us to specify the stub for a particular component rather than using an auto-stub when shallow mounting. So the trick is to "unstub" animated-button by using its original component definition as the stub so it retains all of its functionality! To do this, let's import the AnimatedButton component at the top of the file. Now, let's go to our test and create a const stubs and assign it an object. We can put AnimatedButton as an object property shorthand. Now, we'll pass in stubs as part of our shallow mount config. We'll also replace the CSS selector with the component definition, as this is the preferred way of using the find method. MyForm.spec.js import { shallowMount } from "@vue/test-utils"; import MyForm from "@/components/MyForm"; import AnimatedButton from "@/component/AnimatedButton" describe("MyForm.vue", () => { it("should commit FORM_SUBMIT when button clicked", () => { const stubs = { AnimatedButton }; const wrapper = shallowMount(MyForm, { stubs }); wrapper.find(AnimatedButton).trigger("click"); ... }); }); Doing it this way should give you a green tick. Wrap up You always want to isolate your components in a unit test, which can easily be achieved by stubbing all the children components with shallowMount. However, if your component is tightly coupled with one of its children, you can selectively "unstub" that component by providing the component definition as a stub and overriding the auto-stub. Become a senior Vue developer in 2020. Learn and master what professionals know about building, testing, and deploying, full-stack Vue apps in our latest course. Learn more
February 7, 2020
by Anthony Gore
· 6,286 Views · 2 Likes
article thumbnail
Top 6 Programming Languages for Mobile App Development
When you start building a mobile app, what languages should be on your radar?
Updated February 7, 2020
by Calvin Austins
· 520,615 Views · 41 Likes
article thumbnail
How To Add AutoComplete Textbox In React Application
In this article we are going to learn how we add AutoComplete textbox in ReactJS. We use Material UI Autocomplete component in this demo.
February 6, 2020
by Sanwar Ranwa DZone Core CORE
· 13,347 Views · 4 Likes
article thumbnail
Design Patterns for Beginners With Java Examples
In this article, learn more about design patterns and look at some Java examples as well as a video.
Updated February 5, 2020
by Ranga Karanam
· 166,852 Views · 53 Likes
article thumbnail
Navigation in a React Native Web Application
In this article, we discuss how to add navigation to a React Native web application with npm's react-navigation module.
February 5, 2020
by Jason Rees
· 11,397 Views · 5 Likes
article thumbnail
Hands-on With Node.js Streams: Examples and Approach
In this article, we cover the basics around Streams and provide examples and use-cases for readable, writeable, duplex, and transform streams.
February 5, 2020
by Shital Agarwal
· 9,168 Views · 5 Likes
article thumbnail
Penetration Test Types for (REST) API Security Tests
Penetration testing for REST API security provides a comprehensive testing method and is supported by a number of open source and proprietary tools.
February 5, 2020
by Hari Subramanian
· 20,547 Views · 4 Likes
article thumbnail
Docker With Spring Boot and MySQL: Docker Swarm Part 3
In this article, we look at how to using Docker Swarm with Spring Boot and MySQL. We then dive into relationships between Worker and Manager nodes.
February 5, 2020
by Sanjoy Kumer Deb
· 21,628 Views · 5 Likes
article thumbnail
Switching From React to Vue.js
If you're caught trying to decide between these two great JavaScript frameworks, read on to get a Vue advocate's opinion on the matter.
Updated February 4, 2020
by Anthony Gore
· 29,482 Views · 17 Likes
article thumbnail
Code Splitting With Vue.js and Webpack
Learn how Vue.js and Webpack can be used to split a single page app into more optimally sized files that can be dynamically loaded.
Updated February 4, 2020
by Anthony Gore
· 15,212 Views · 7 Likes
article thumbnail
Vue.js Single-File JavaScript Components in the Browser
Browser support for native JavaScript modules is finally happening. In this article, we show you what this means for Vue.js developers.
Updated February 4, 2020
by Anthony Gore
· 22,950 Views · 8 Likes
article thumbnail
Avoid This Common Anti-Pattern in Full-Stack Vue/Laravel Apps
In this post, we'll look at a design pattern that makes it easy to inject initial application state into the head of the HTML page, and allows for a lot of flexibility.
Updated February 4, 2020
by Anthony Gore
· 10,400 Views · 5 Likes
article thumbnail
4 AJAX Patterns for Vue.js Apps
A Vue.js expert demonstrates different AJAX patterns that can be used with Vue.js and Vuex, and gives some sample JavaScript code for each example.
Updated February 4, 2020
by Anthony Gore
· 17,317 Views · 7 Likes
article thumbnail
What Is a Service in Angular and Why Should You Use it?
A software engineer introduces the concept of services in the Angular web development framework and how they work with the other components.
Updated February 4, 2020
by Devquora Sharad
· 105,539 Views · 9 Likes
  • Previous
  • ...
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×