Cable news networks had reason to feel bittersweet about the end of 2016 as Donald Trump’s historic campaign for the White House drove their ratings to record levels. But in the days leading up to his inauguration as the 45th president of the United States, Trump’s continuing love-hate relationship with them provided a compelling sequel.

CNN, Fox News and MSNBC have seen a surprising surge in their audience levels this month as they report in real time on the unpredictable saga of Trump, who can dictate their programming day with his Twitter account.

The cable news networks will be now be covering a president whose distrust and ridicule of the media is unlike anything they have seen from a commander in chief.

While it’s apparent Trump’s combative nature is lifting viewer interest, the uncharted territory of his presidency is likely to test the journalistic spine of the organizations as well.

“He is the most ripe target for legitimate journalistic investigation that’s come along in decades because of how he so blatantly positions himself as a rule breaker and a game changer, a guy that challenges orthodoxy,” said Jonathan Klein, a veteran TV news executive who was president of CNN from 2004 to 2010. “The real journalists out there must be licking their chops about the opportunity to investigate all that.”

Frank Sesno, a former CNN Washington bureau chief and director of the School of Media and Public Affairs at George Washington University, said the unprecedented nature of an outsized personality such as Trump entering the White House without any government experience or clear ideological road map makes it “a time of purpose” for cable news.

“The conversation has never been more important and the national mood more unsettled, certainly not in decades,” Sesno said.

As a result, an expected post-election downturn in cable news ratings hasn’t happened. Ratings leader Fox News is up 24 percent this month compared with January 2016, when the presidential primary season was kicking into high gear. CNN has gained 15 percent in viewership, while MSNBC has increased 36 percent during the same time period, according to Nielsen data.

“It’s like the campaign never ended,” said one cable news producer who spoke on the condition of anonymity.

Cable networks seem to be doubling down. CNN anticipated depending more on series programming in 2017. But with Trump’s arrival, it has added more contributors to its political team that was already augmented for the 2016 campaign. Among the new hires is Washington Post reporter David Fahrenthold, who distinguished himself last year with his investigations of Trump’s charitable foundation.

MSNBC’s liberal-leaning prime-time anchors have seen a ratings surge as they provide a nightly campfire for shocked Hillary Clinton voters anxious about the new administration. The channel has also made its dogged campaign correspondent Katy Tur, a frequent target of Trump’s ire, a daily daytime anchor for the first 100 days of the new administration.

Fox News has capitalized on the surprise GOP victory by adding conservative commentator Tucker Carlson at 9 p.m. to replace Megyn Kelly, who was more critical in her coverage of Trump than the network’s other prime-time anchors. The move offered its core audience of Republican viewers a full block of politically right-leaning commentary programs in prime time. A Pew Research Study said 40 percent of Trump voters received their election news from Fox.

Carlson told the Los Angeles Times recently that he doesn’t intend to be a cheerleader for Trump or anyone else, and that he will focus on the incoming president’s policies rather than his bombastic rhetoric.

“He’s so florid and so mesmerizing and interesting or appalling, depending on your point of view,” Carlson said. “He’s just so big as a presence that he tends to obscure what he’s saying.”

No matter which way viewers lean politically, their intense interest isn’t likely to subside any time soon.

“Once the public is satisfied that the world is not going to end and a nuclear war is not going to break out or that civil unrest isn’t going to erupt across the country they may reduce their viewing,” Klein said. “But in the first month of the Trump administration they will be sitting at the edge of their seats.”

During the primary season, some critics saw CNN — which tries to stay in the middle lane between its politically leaning competitors — as being too accommodating to Trump during the campaign because of his audience appeal. CNN President Jeff Zucker was highly attuned to Trump’s audience appeal, having put the real estate mogul’s reality show “The Apprentice” on NBC.

But CNN has covered the incoming Trump administration aggressively, scoring a major scoop with its report that the president-elect had been briefed by intelligence officials about unverified allegations in a dossier that the Russians had compromising personal information about him.

“They were clear about what their reporting was, why they did it, and what they did and did not do,” Klein said. “They were aggressive in defending their actions.”

The network gave strong support to its correspondent Jim Acosta after an angry Trump refused to call on him at a news conference and incorrectly accused the network’s report as being “fake news.” Insiders at CNN say privately they have been energized by the powerful effect of the dossier story, which has since been confirmed by the FBI.

Trump takes shots most often at CNN because it’s the channel he watches most often. The ongoing tension has led to speculation that parent company Time Warner would spin off the channel to keep it from getting in the way of its proposed $85.4 billion merger with telecom giant AT&T.

Trump has said he is opposed to the deal — an odd message from an incoming president who during the campaign said American business is constrained by too much regulation. But AT&T Chairman Randall Stephenson dismissed the possibility of a spinoff in an interview this week. Executives at CNN say privately the merger never comes up in discussions of news coverage.

CNN declined to comment.

Other presidents have clashed with the media. President John F. Kennedy ordered the tapping of reporters’ phones. President Richard Nixon’s aides orchestrated letter-writing campaigns in major cities to complain to NBC when they saw a segment on the evening news that they were unhappy about. President Barack Obama has accused Fox News, home of his harshest media critics throughout his presidency, of portraying him as a fictional character.

But as president-elect, Trump’s pugnacious approach to the media, and his frequent use of social media to lambaste, is raw and immediate. He acts frequently and with condemnation that is not always based in fact. His most recent target was NBC’s “Today,” which aired a report that said he had little to do with the recent decisions by U.S. companies to keep jobs from going overseas.

“No wonder the Today Show on biased NBC is doing so badly compared to its glorious past. Little credibility!” he wrote on Twitter. (“Today” has actually spent more than a year on top of the ratings among the advertiser-targeted audience of 25- to 54-year-olds.)

Trump’s rants against news outlets could become less effective over time if he continues to call out reporting that proves to be accurate.

“There was no such thing as a camera piece of publicity that Donald Trump didn’t like,” Sesno said. “He is now conferring that upon news organizations. He actually threatens to raise their profiles in ways he may not want.”