Testing Vue Components With Jest

js testing handbook! This is a collection of short, focused examples on how to test Vue components. Welcome to part 4 of a series on how to test a Vue component. And there you have it! We have looked at how to do some basic testing of our React components using Jest, Enzyme, and Sinon. Anything else is just looking at what components return. Jest is useful for testing the rendering of React components. Created by Edd Yerburgh, Submitted by Eremenko Stanislav. Its primary guiding principle is:. # Object mode. 本文章向大家介绍jest+vue-test-utils初步实践,主要包括jest+vue-test-utils初步实践使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。. Depending on the choice of a JavaScript framework we often decide a test runner which is most compatible or recommended with our framework. js Dec 20, 2017 | Aurélien Bottazini Unit testing is a skill on its own, and it may not be your priority while you are learning a new language or a new framework. Jest acts as a test runner, assertion library, and mocking library. In this article below we will test a component which runs asynchronous code inside of its componentDidMount lifecycle event. json file shipped with the library. npm install --save-dev jest. vue component and we have a single empty test which will check that it (the component) displays items from the list. js Component? There are many strategies we can use to test a React. what I'm trying to do is when the button is clicked, login methods is has been called. We have run the sample which is on the aurelia. js Components With Jest and Puppeteer Posted on 3 March 2019 , by Markus Oberlehner , in Development , tagged Front-End Architecture , JavaScript , TDD and Vue Note: This is the sixth part of my “Advanced Vue. Click on the program name to find more information. Testing typescript classes with Jest and Jest Mocks 12 April 2017 on typescript, unit testing, jest, mock. Running Our Existing Test. At work I've recently started using Vue as my main front-end framework instead of Angular 1. It's one of these stories when we don't even know what is the question, so it's difficult to ask Google. This method will create a Wrapper that contains the mounted and rendered Vue component. npm i vue-test-utils --D. js applications shouldn't be understated and Jest makes this easier than ever. js and Electron to build and secure modern desktop applications. With that being said, you can test interactions with your store within your smart components:. On the other hand, tests must be written and maintained. On the one hand, having a solid test suite makes code easier to refactor, and gives confidence that it works the way it should. Its primary guiding principle is:. For more on this, check out "How to Test React Components Using Jest". Testing is the process of verifying that our test assertions are true and that they stay true throughout the lifetime of the application. I didn't go with Mocking CSS modules. In my project I have Vue component that contains Data Grid inside. That was not enough yet for testing my React components though. Follow along with Alex as he shows you the ins and outs of unit testing with Jest. They have a cost, like any other code. With this library, testing of data types is much easier and more enjoyable. #javascript #jest #node #testing Jest explicitly or arbitrarily force fail() a test. We have run the sample which is on the aurelia. Unit testing Vue. The project pages claims: Easily test props, events, and slots (including named slots) Optionally shallow render components Simulate simple DOM events (click, input, etc. 0 - free and beautiful Vue. vue-jest-unit-test. Please make sure to read the Contributing Guide before making a pull request. Learn shallow rendering, snapshot testing and dependency mocking, among other techniques. Vue CLI には、Jest または Mocha を使って難しい設定なしにユニットテストするための組み込みのオプションがあります。カスタムセットアップのためのより詳細なガイダンスとなる公式の Vue Test Utils もあります。 単純なテスト. js components with Jest by Alex Jover Morales (@alexjoverm) Jest for all: Episode 1 — Vue. Explore the top new features and download WebStorm 2018. Codebrains Newsletter. Any solid software will be built with testability in mind; And React is not an exception to that. It has all the necessary utilities to test single-file components, including those using Vue Router or Vuex. js - Vue Test Utils. (found in anonymous component - use the "name" option for better debugging messages. Welcome to the Vue. An example project for this setup is available on GitHub. js components can be tricky. js Component? There are many strategies we can use to test a React. October 2017: the article was updated to React 16 and Enzyme 3. As we’re inside of the Vue. Author Edd Yerburgh, creator of the Vue testing utility, explains the best testing practices in Vue along with an evergreen methodology that applies to any web dev process. This means that it successfully imported your component, but it can’t yet understand. In this article, I'll show you how to mock a module file in Jest by replacing it in your component's graph of dependencies. Testing results in software that has fewer bugs, more stability, and is easier to maintain. 单元测试应该: 可以快速运行; 易于理解; 只测试一个独立单元的工作. When props is set to true, the route. what I'm trying to do is when the button is clicked, login methods is has been called. Unit testing Vue class components using typescript, chai & sinon – My findings One day, not so very long ago I was creating an npm package containing a vue. You can now start writing tests for your Vue components 🎉 Credits This post is the result of gathering many documentation around the web such as Jest official docs, this post, and many more. I tried to import axios to my *spec. Unit testing is a software testing method where the individual units/ components of a software are tested to verify that each unit works as expected. Since it depends on the Vuex store which, in its turn, highly depends on Firebase, we must do … - Selection from Vue. You may prefer unit tests because it is fast, quick to set up, and deterministic, but you wonder how to unit test your React components ? Have you tried Jest snapshots ? 1) Set up a basic application:. reactjs - jest snapshot testing nested redux "connected" components (React JSX) - Codedump. js, Firebase, and Vue components. @vue/test-utils で「 has been modified to ensure it has the correct instance properties」と言われた時 Vue. But what happens when you want to test event handlers that must be bound to the window ?. Jest allows for an exceptional unit testing experience. But that is not everything! To ease a little a bit testing I used two libraries more: enzyme and sinon. While jsdom is only an approximation of how the browser works, it is often good enough for testing React components. I don't understand the advantage of unit testing a vue. Install enzyme to help us test our React components; Add automated tests around our ChordEditor component. We also have the official Vue Test Utils which provides more detailed guidance for custom setups. If you have prior experience with Jest, you can skip ahead and use the GitHub code as a starting point. Creating a Store without Vuex in Vue. vue files, and babel-jest for the integration with Babel. # Object mode. js, Firebase, and Vue components. Get your GED using official GED test study material, classes, and practice questions. io • Issue #98 • View online. First, note the test script to run jest against a set of files in the tests directory. vue-jest-utils Utilities for testing Vue. Last chapter we built our first component; this chapter extends what we learned to build TaskList, a list of Tasks. This means that it successfully imported your component, but it can’t yet understand. Using Jest to unit test Vue. There are two problems with testing components that use React Intl with Enzyme and  Jest : injectIntl higher-order component will break shallow rendering because it will render a wrapper component instead of your component. If you’re having trouble setting up, clone the avoriaz mocha example project, and then you can begin your tests. Let's walk through to one of the most useful unit test functions. Testing the user interface is perhaps what our tool, Cypress. js apps I use vue-test-utils which contains all the utilities you need for testing Vue components. For more on this, check out “How to Test React Components Using Jest”. Example repositories testing Vue components with jest and vue-jest: Avoriaz with Jest; Vue Test Utils with Jest; Supported langs. Jest is a test runner developed by Facebook, aiming to deliver a battery-included unit testing solution. Just run yarn add --dev @vue/test-utils and you are good to go. It is the "best of both worlds" as you don't need a server but still have SEO benefits because Nuxt will pre-render all pages and include the necessary HTML. Link can not be used outside a Router. The easiest way to start with testing React components is doing snapshot testing, a testing technique that lets you test components in isolation. UI testing. js components with no configurations using Jest. #Getting Started # Vue CLI If you are not interested in manually setting up webpack, it is recommended to scaffold a project with Vue CLI instead. This makes React UI testing easy to automate. This post is the result of gathering many documentation around the web such as Jest official docs, this post, and many more. In this lesson, we'll use Jest to unit test a Counter component built with Vue. If you are familiar with testing software, it’s just like unit testing you do for classes: you test each component functionality. vue file’s format. A test contains one or more expectations that check the state of the code. Anyone care to explain? From my perspective the front end application should rather be tested with Selenium to really see how it behaves to the end user. Let’s talk a bit on those. js Application Architecture” series on how to structure and test large scale Vue. Like unit test your component functions or test interactions. Make sure that your current configuration is not already processing the SVG files. He was previously on the Angular core team at Google, and built the dependency injection, change detection, forms, and router modules. js Application Architecture” series on how to structure and test large scale Vue. We also set up the. Testing Vue components using Jest. Jest is a JavaScript test framework. I need to test the behavior that is connected with onActionBegin callback of the grid. I don't understand the advantage of unit testing a vue. I assume you created a React app with create-react-app, which already comes with Jest installed, the testing package we'll need. react-test-renderer is primarily for snapshots, while enzyme is for whenever you need to actually interact with the component, like simulate clicking it, feed it new props and see how it changes, etc. #javascript #jest #node #testing Jest explicitly or arbitrarily force fail() a test. Our test checks if the components call the get function from our mock after rendering and running it will result with a success. In the line of code above, the Jest expect function is set to check if the content of the variable html is the same as Welcome to React. He then explored testing simple Vue Components to see how we can effectively test and store the rendered output with snapshots. Testing Vue. As well as running tests, Jest comes with a load of other features out the box, like mocks, code coverage and snapshot testing. Email Address. Testing React components can be a difficult task to do especially when you're just starting with it. Typescript is a powerful way to build applications. Before we get to the guidelines, let's first get familiar with the following example component that we'll be testing. I don't understand the advantage of unit testing a vue. In this article, we will be going through writing tests for React using Enzyme and Jest. So I create my SearchPodcastForm. Vue Test Utils is the official library for unit testing Vue components. json file shipped with the library. Each it() in a test suite corresponds to a test or a spec. At work I’ve recently started using Vue as my main front-end framework instead of Angular 1. Jasmine and Jest can be categorized as "Javascript Testing Framework" tools. Testing a login component with Jest. I'll assume you've already had an introduction to Jest and Vue Test Utils. On the other hand, tests must be written and maintained. 0 and Jest must be installed as well. It’s one of the fastest testing frameworks for Vue single file components (SFCs). For more info on Jest you can look here. js admin template with 44+ custom UI components. In FileMaker Web Apps Part I of this series we focused on how you can use Vue. Not only will you learn the necessary tooling, but we'll also review the ins and outs of testing your client-side code. Author of Test Vue. js environment, we'll also be using vue-test-utils to make it easy when interfacing with native Vue elements. Jest is amazing! It is out of the box , takes way less time to run the tests than mocha. Ya que no voy a profundizar en el uso de JEST, si lo necesitas, tienes la documentación oficial y también un curso de test unitarios usando JEST en mi blog. The best way to handle those components is to export them twice as follows:. Let's walk through to one of the most useful unit test functions. js and React, just installed and made Jest work, however my first test is failing with. Jest can be combined with Enzyme or React Testing Library to test your React components in an even more powerful way. test-vue-app - Test Vue. On the other hand, TestStore should NOT be used when we want to unit test components which do not inject NgRx Store and receive all their data through @Input() bound. In this tutorial, we are going to learn about how to unit test vue. What makes Vue special in this regards, it’s quite convenient to test for it’s approach in simplicity and leveraged functions and objects wherever possible. Unit tests validate the code in isolation. Created by Edd Yerburgh, Submitted by Eremenko Stanislav. Testing connected components: You may see the above example and think that sometimes components are much more complex so it is not possible to test them in isolation. What is Jest. mount allows us to wrap that component and get access to the Vue instance and several helper methods around it. Unit Testing Stencil makes it easy to unit test components and app utility functions using Jest. Unit Testing Vue Components is a pretty self-explanatory title for this article. Matt Maribojoc shows us how to test a Vue Project with Jest and Nightwatch. js component: We can verify that a particular function in props was called when certain a event is dispatched. Jest snapshot testing captures your component's HTML output. Testing Vue components using Jest. Select with search. CSS/Style Testing. Testing Smart Components. It also coverer Vuex and Vue. On peut trouver quelques guides dans la documentation de Vue Test Utils. People is excited about it. Anything else is just looking at what components return. Jest is a test-running and assertion library released by Facebook, and. Vue Test Utils is the official library for unit testing Vue components. Without it, we would only be able to write tests against plain JavaScript code, not Vue. ) Use any test runner / assertion library VueUnit renders all components in the DOM…. Edd Yerburgh - Unit testing Vue components Why test, what to test, and how to test Vue components - Duration: 26:08. Using Jest to unit test Vue. In a magical world, we could write our code. Snapshot testing with Jest. When they don’t match, your test fails, indicating that something has changed. Jest snapshots are a very useful tool when it comes to preventing unexpected changes in your UI/functions. That was not necessary for me. I'll assume you've already had an introduction to Jest and Vue Test Utils. Unit Testing. Depending on the choice of a JavaScript framework we often decide a test runner which is most compatible or recommended with our framework. Projects created by Vue CLI are pre-configured with most of the common development needs working out of the box. On the other hand, tests must be written and maintained. We need a separate Vue Test Utils (@vue/test-utils) scoped package in order to virtually mount our components and use Jest to execute the…. Vue provides a way to build apps for any deployment target by reusing existing code. Unit Test Lightning Web Components with Jest. [Vue warn]: Failed to mount component: template or render function not defined. Custom jest config. Unit tests should be: Fast to run; Easy to understand; Only test a single unit of work. Making Jest work with Vuex, Nuxt. It's a unit testing utility library that makes testing easier. An example project for this setup is available on GitHub. js component methods using jest and vue-test-utils. You write a snapshot test and run it. They also touch on snapshot testing, the Vue Jest library, and more!In particular, we dive pretty deep on: Edd intro Maintains Vue Test Utils What is Vue Test Utils? Library to make unit testing Vue components easier What is a mounted component? Would you use Vue Test Utils by yourself?. To test my Vue. js component: We can verify that a particular function in props was called when certain a event is dispatched. Using Enzyme For DOM Testing I hope it’s clear. In this section we'd like to link to community posts and articles about integrating Jest into other popular JS libraries. If you don’t have it installed already, just run npm install -g @vue/cli in your terminal. FileMaker Web Portals with Vue. Product Test Technician at Tektronix Component Solutions Beaverton, Oregon. (found in anonymous component - use the "name" option for better debugging messages. io web site for testing components, we are using jest, we had successfully tested a value converter with it,however, in testing custom elements we faced two problems: Cann…. Testing React components with Jest I'm trying to get started on TDD on Node. json file shipped with the library. js component for a large scale code base. Vue's baked in testing library provides the necessary functionality to render components, invoke methods, and make assertions. Testing React Components: who this guide is for and what you need to know. vue-test-utils公式を参照するのがオススメです。 今回は紹介しませんが、Jest以外のテストランナーやTypeScriptでのテスト手法も解説されています。 環境構築. Jest alone can't do that. To do so, we'll use the Vue Test Utils library. shallow rendering comparison (test utils and Enzyme). Testing is the process of verifying that our test assertions are true and that they stay true throughout the lifetime of the application. Vue CLI で構築したプロジェクトには、すでに以下テスト( tests/unit/example. npm install -g vue-cli vue init webpack vue-jest. The main method that it exports is the { mount } method, which takes a component and mounts it, and returns a wrapper than contains the mounter component instance as well as helper methods to assert and render against the component render tree. Testing connected components: You may see the above example and think that sometimes components are much more complex so it is not possible to test them in isolation. This is a pretty complex subject and usually we do it by comparing images. To start with, we want to use the Vue CLI to setup our build system, and enable Storybook and Jest testing in our created app. jest-vue-preprocessor is needed for making jest understand. js and React, just installed and made Jest work, however my first test is failing with. I provided lite version of my samples in the attachment. The vue-cli webpack template comes with either Karma or Jest, both well supported test runners, and there are some guides in the Vue Test Utils documentation. I didn't find any reference of Jest outside React before writing this article, I hope this will be the first. js projects. A concise guide to testing Vue. Testing a single page application can be quite hard when it comes to validating the HTML that is generated by your components. Snapshot testing with Jest. Jest is a zero configuration test runner that allows you easily write JavaScript tests without setting anything up. The power of Snapshot Testing in Vue. This is it, with this part and the first one, we pretty much covered (I hope) unit testing of your React Native components + your state management logic. Testing an AngularJS app with Jest by Matthieu Lux. For recursive components, make sure to jest-setup. Check this FAQ section if you want to use both inline and external SVGs. We will also overcome some of the common issues faced during the installation of Jest. To render your component in Jest unit tests, use either react-test-renderer or enzyme. Instructor: I have a very basic counter component that I've created with Vue. js apps I use vue-test-utils which contains all the utilities you need for testing Vue components. You can learn to test your Vue. It uses vue-test-utils, the official library for testing Vue components, and Jest, a modern testing framework. Ces deux test runners sont très bien supportés par Vue. In this article, using a toy application you'll see the power of Jest. Demo project for Tips for Unit Testing Vue Components with Jest. In my last post, I covered unit testing React components using Jest. Snapshot Testing. These components have been traditionally called container or smart components. For more on this, check out "How to Test React Components Using Jest". Testing React Components: who this guide is for and what you need to know. Makes life so much easier. These tests record snapshots of rendered component structure and compare them to future renderings. Mounting a component. I’m using create-app-react so I already have jest. However, in the snapshot testing paradigm, every time you act on a component, Jest takes a “snapshot” of the entire rendered DOM output; in simpler terms, Jest basically converts your rendered component to a string. js components 9. Testing connected components: You may see the above example and think that sometimes components are much more complex so it is not possible to test them in isolation. js applications thoroughly using Jest with this interactive course. The vue-cli webpack template comes with either Karma or Jest, both well supported test runners, and there are some guides in the Vue Test Utils documentation. The JSX syntax allows. 2 years ago. Building Large-Scale Apps. These tests record snapshots of rendered component structure and compare them to future renderings. Have you ever wanted to use. What makes Vue special in this regards, it’s quite convenient to test for it’s approach in simplicity and leveraged functions and objects wherever possible. js Component? There are many strategies we can use to test a React. That was not necessary for me. The following is an example of a test that ensures that a Vue component, Component. By default searchable is set to true, thus using search doesn’t require any prop. This is how we tie the feature specification to implemented test code. How to test Vue components effectively with Jest and vue-test-utils. There was no clear way of unit testing vue class components that had separate typescript, html, css files and no vue files, without using webpack. Setup Vue Storybook. I still had some failures. The example component we are testing now. So it would be useful to show that testing React component using Jest is not so difficult too. The source and contribution guides (anyone is welcome!) is here and the book is here. vue-jest-unit-test. There are several moving parts of Vue CLI - if you look at the source code, you will find that it is a monorepo containing a number of separately published packages. js at the root of our project. UI testing. GitHub Gist: instantly share code, notes, and snippets. Jest is my unit-testing tool of choice. being re-used by Vue's render patch optimization routines). To start with, we want to use the Vue CLI to setup our build system, and enable Storybook and Jest testing in our created app. Learn shallow rendering, snapshot testing and dependency mocking, among other techniques. 9/11 of the new JavaScript unit testing framework and was not and/or test needed jQuery from a bower_components directory?. js applications shouldn't be understated and Jest makes this easier than ever. Basics of unit testing with Jest; 2. Jest provides you with multiple layers on top of Jasmine. Without it, we would only be able to write tests against plain JavaScript code, not Vue. Unfortunately, React Native has many environmental dependencies that can be hard to simulate without a host device. Unit tests should be: Fast to run; Easy to understand; Only test a single unit of work. js and update your package. Example scenario. Enzyme provides the testing utility functions for React components such as shallow, mount and render whereas Jest is a test runner and an assertion library. mount allows us to wrap that component and get access to the Vue instance and several helper methods around it. The vue-cli webpack template comes with either Karma or Jest, both well supported test runners, and there are some guides in the Vue Test Utils documentation. This makes React UI testing easy to automate. Frontend is written with Vue. 위 코드는 str의 값이 Hello World가 맞는지 확인하는 테스트 코드입니다. js components using jest and vue-test-utils. Have you ever wanted to use. This is very similar to the test we just wrote, so I recommend you give it a try now to make sure you understand how Jest works. Real-World Example. Note that I’m testing React components using Jest. All was going well until I tried to unit test the vue component. People is excited about it. Specifying a primary-key column can alleviate this issue (or you can place a unique :key on your element/components in your custom formatted field slots). Vuejs Amsterdam takes place the greatest Conference Venue in the World Theater Amsterdam on February 20th & 21st 2020. Much like isVisible for v-show, vue-test-utils provides an exists method to be used when testing elements conditionally rendered using v-if. js Dec 20, 2017 | Aurélien Bottazini Unit testing is a skill on its own, and it may not be your priority while you are learning a new language or a new framework. The following is an example of a test that ensures that a Vue component, Component. I have ran Jest tests before and I like how it works but haven’t written any myself. I'm writing test for components which uses axios. For a full list of its functionalities visit the documentation. It has a relatively shallow learning curve and has enough similarities with both React and Angular 1 that if you’re familiar with one or both of them it feels quite familiar. A Vue CLI 3 plugin for Electron with no required configuration. On the one hand, having a solid test suite makes code easier to refactor, and gives confidence that it works the way it should. #javascript #jest #node #testing Jest explicitly or arbitrarily force fail() a test. Learn how to get started with Jest through the Jest website's React Tutorial. js testing handbook! This is a collection of short, focused examples on how to test Vue components. Snapshot testing can be quite helpful, especially in larger applications. What to test in a React Component. js applications, I'm using Vue Test Utils as the javascript testing utility. It is a test runner, assertion library, and offers spies, stubs and mocks as well. js component is created 11. Jest also supports snapshot testing, which can be really handy for preventing accidental UI regressions when doing React development. That was not enough yet for testing my React components though. Like unit test your component functions or test interactions. In this lesson, we'll use vue-testing-library along with Jest to write some integration tests for a Counter component. The fact-checkers, whose work is more and more important for those who prefer facts over lies, police the line between fact and falsehood on a day-to-day basis, and do a great job. Today, my small contribution is to pass along a very good overview that reflects on one of Trump’s favorite overarching falsehoods. Namely: Trump describes an America in which everything was going down the tubes under  Obama, which is why we needed Trump to make America great again. And he claims that this project has come to fruition, with America setting records for prosperity under his leadership and guidance. “Obama bad; Trump good” is pretty much his analysis in all areas and measurement of U.S. activity, especially economically. Even if this were true, it would reflect poorly on Trump’s character, but it has the added problem of being false, a big lie made up of many small ones. Personally, I don’t assume that all economic measurements directly reflect the leadership of whoever occupies the Oval Office, nor am I smart enough to figure out what causes what in the economy. But the idea that presidents get the credit or the blame for the economy during their tenure is a political fact of life. Trump, in his adorable, immodest mendacity, not only claims credit for everything good that happens in the economy, but tells people, literally and specifically, that they have to vote for him even if they hate him, because without his guidance, their 401(k) accounts “will go down the tubes.” That would be offensive even if it were true, but it is utterly false. The stock market has been on a 10-year run of steady gains that began in 2009, the year Barack Obama was inaugurated. But why would anyone care about that? It’s only an unarguable, stubborn fact. Still, speaking of facts, there are so many measurements and indicators of how the economy is doing, that those not committed to an honest investigation can find evidence for whatever they want to believe. Trump and his most committed followers want to believe that everything was terrible under Barack Obama and great under Trump. That’s baloney. Anyone who believes that believes something false. And a series of charts and graphs published Monday in the Washington Post and explained by Economics Correspondent Heather Long provides the data that tells the tale. The details are complicated. Click through to the link above and you’ll learn much. But the overview is pretty simply this: The U.S. economy had a major meltdown in the last year of the George W. Bush presidency. Again, I’m not smart enough to know how much of this was Bush’s “fault.” But he had been in office for six years when the trouble started. So, if it’s ever reasonable to hold a president accountable for the performance of the economy, the timeline is bad for Bush. GDP growth went negative. Job growth fell sharply and then went negative. Median household income shrank. The Dow Jones Industrial Average dropped by more than 5,000 points! U.S. manufacturing output plunged, as did average home values, as did average hourly wages, as did measures of consumer confidence and most other indicators of economic health. (Backup for that is contained in the Post piece I linked to above.) Barack Obama inherited that mess of falling numbers, which continued during his first year in office, 2009, as he put in place policies designed to turn it around. By 2010, Obama’s second year, pretty much all of the negative numbers had turned positive. By the time Obama was up for reelection in 2012, all of them were headed in the right direction, which is certainly among the reasons voters gave him a second term by a solid (not landslide) margin. Basically, all of those good numbers continued throughout the second Obama term. The U.S. GDP, probably the single best measure of how the economy is doing, grew by 2.9 percent in 2015, which was Obama’s seventh year in office and was the best GDP growth number since before the crash of the late Bush years. GDP growth slowed to 1.6 percent in 2016, which may have been among the indicators that supported Trump’s campaign-year argument that everything was going to hell and only he could fix it. During the first year of Trump, GDP growth grew to 2.4 percent, which is decent but not great and anyway, a reasonable person would acknowledge that — to the degree that economic performance is to the credit or blame of the president — the performance in the first year of a new president is a mixture of the old and new policies. In Trump’s second year, 2018, the GDP grew 2.9 percent, equaling Obama’s best year, and so far in 2019, the growth rate has fallen to 2.1 percent, a mediocre number and a decline for which Trump presumably accepts no responsibility and blames either Nancy Pelosi, Ilhan Omar or, if he can swing it, Barack Obama. I suppose it’s natural for a president to want to take credit for everything good that happens on his (or someday her) watch, but not the blame for anything bad. Trump is more blatant about this than most. If we judge by his bad but remarkably steady approval ratings (today, according to the average maintained by 538.com, it’s 41.9 approval/ 53.7 disapproval) the pretty-good economy is not winning him new supporters, nor is his constant exaggeration of his accomplishments costing him many old ones). I already offered it above, but the full Washington Post workup of these numbers, and commentary/explanation by economics correspondent Heather Long, are here. On a related matter, if you care about what used to be called fiscal conservatism, which is the belief that federal debt and deficit matter, here’s a New York Times analysis, based on Congressional Budget Office data, suggesting that the annual budget deficit (that’s the amount the government borrows every year reflecting that amount by which federal spending exceeds revenues) which fell steadily during the Obama years, from a peak of $1.4 trillion at the beginning of the Obama administration, to $585 billion in 2016 (Obama’s last year in office), will be back up to $960 billion this fiscal year, and back over $1 trillion in 2020. (Here’s the New York Times piece detailing those numbers.) Trump is currently floating various tax cuts for the rich and the poor that will presumably worsen those projections, if passed. As the Times piece reported: